aspose file tools*
The moose likes Security and the fly likes RSA, Private Key Generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "RSA, Private Key Generation" Watch "RSA, Private Key Generation" New topic
Author

RSA, Private Key Generation

Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Hello All,

I am implementing RSA for a Project.
Now, i have a string using which i have to generate private keys.
When i saw the C implementation for the same, i got that there is library R_ENCODE.c which is having a Function R_DecodePEMBlock. This function takes the Common String as argument and return me with the Object of Private Key.
Can anyone tell me how to implement this in java. So that i can have Private key and than i can use RSA for decryption.

Thanks,
Tarun Khandelwal
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

You should post the code you have so far so that we can help you with it.
Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Hello Tim,

Till now i haven't started developing.
Actually ii am stucked in the beginning. I have RSA implementation in C.
Now i have to implement the same in Java.
In C I was getting private key after passing My Corporate Key into the Function R_DecodePEMBlock of class R_ENCODE.c

So can you please tell me is there any class in java also, using which i can retrieve the Private Key.

Thanks,
Tarun Khandelwal
Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Hello Everyone,

I have to Implement RSA Decryption. For that i think i will be requiring Private Key.
I am receiving a file which is being created by c code. Where the key is generated using R_ENCODE.c class , function :- R_GeneratePEMKeys.
Than the buffer is being passed to R_EncodePEMBlock.

I am not getting how to get Private Key Object from that file?
Waiting for Response.

Thanks,
Tarun Khandelwal
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Tarun Khandelwal wrote:
I have to Implement RSA Decryption. For that i think i will be requiring Private Key.
I am receiving a file which is being created by c code. Where the key is generated using R_ENCODE.c class , function :- R_GeneratePEMKeys.
Than the buffer is being passed to R_EncodePEMBlock.

I am not getting how to get Private Key Object from that file?


In Java, public/private key pairs are generated with the KeyPairGenerator. In your case, since the data has already been encrypted, the pairs have already been generated by the C-program. Technically, you are "regenerating" the private key, but I digress...

Anyway, you just need to create the key object, which is done with one of the java.security.spec.KeySpec -- and following the JavaDoc for that class, I suspect that you need the RSAPrivateKeySpec.

Unfortunately, RSA is not an encryption that I use much (if at all), so I have no idea how to load it from a pem file. But hopefully, I gave you enough to get started (via research).

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40


Looks like this is done with one of the encoded key specs -- java.security.spec.EncodedKeySpec (specifically, one of the subclasses) class. The reason this is needed is because the key file is encoded, so you need to decode it before it can be used.

Henry
Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Thanks Henry,

You are absolutely correct.
The KeyPair is being generated before by the C code.
Now i have to load the Private key from the object that i am getting from C.

I will look into your suggestion.
But it would be great if i get how to load the file.

Thanks
Tarun Khandelwal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RSA, Private Key Generation