• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RSA, Private Key Generation

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should post the code you have so far so that we can help you with it.
 
Tarun Khandelwal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic