Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to generate base64-encoded DER format of private key

843811Mar 6 2008 — edited Mar 6 2008
Hi Experts,

I am kind of confused with all these formats. In the following code, what format is the keys in?
If they are not DER formatted then how can I get base64-encoded DER format of private key and public key?
Any help is greatly appreciated... Thanks,
public void generateKeys( )
    {
        String retValue = null;
        BASE64Encoder myB64 = new BASE64Encoder();
        try
        {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(2048);  
            KeyPair keypair = keyGen.generateKeyPair();
            Key privKey = keypair.getPrivate();
            Key pubKey = keypair.getPublic();
            m_PrivateKey = myB64.encode(privKey.getEncoded());
            m_PublicKey = myB64.encode(pubKey.getEncoded());
         }
         catch(Exception ex){}
}
Edited by: mehala on Mar 6, 2008 9:17 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2008
Added on Mar 6 2008
1 comment
1,567 views