Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 31
Registered: ‎08-05-2011
My Device: 9550
My Carrier: Vodafone

Getting PEM key to form an instance of RSA Public key

Hi,

 

I had posted this in other thread, but felt dat this should be started in a new thread.

 

My Question is how to get that PEM key from the webservice

I get the public key from the webservice its like this

-----BEGIN PUBLIC KEY-----


// the key goes here


-----END PUBLIC KEY-----

 

I remove the other tags to get the Public key form the rest of the string so as to retrive the public key.

 

 

    public static RSAPublicKey readPublicKey(String strPEMKey) {

        RSAPublicKey publicKey = null;
        X509Certificate clientCert = null;

        byte[] certBuf = null;

        try {

            certBuf = Base64InputStream.decode(strPEMKey);

        } catch (Exception ex) {

            ex.printStackTrace();
        }
        try {

            clientCert = new X509Certificate(certBuf);
            publicKey = (RSAPublicKey) clientCert.getPublicKey();

 

//But i get the public key as NULL always

 

        } catch (CertificateParsingException ex) {
            ex.printStackTrace();
        } catch (InvalidCryptoSystemException ex) {
            ex.printStackTrace();
        }
        return publicKey;
    }

 

 

 

My signature verification function is as follows

 

    public static boolean verify(RSAPublicKey publicKey, byte[] data,
            byte[] signature) throws CryptoException {
        PKCS1SignatureVerifier verifier = new PKCS1SignatureVerifier(publicKey,
                signature, 0);
        verifier.update(data);
        return verifier.verify();
    }

 

This method is from the AdvancedCryptoDeveloperLab.java class that i found on the Developers forum and it is dhared by many users in other thread also.

 

I want to verify the RSA signature that is sent by other webservice using the verify() function above. I have the the "RSA Signature" stored in a string and the "Plaintext" in other string that i converted to bytes to Verify the signature. But the Public Key is always giving me as NULL.

Can any one help me here...Please.


/*********************************************************************/
Please press the like button on the right side to thank me if my reply helped you and please mark posts as solved if you found a solution.
Contributor
Posts: 12
Registered: ‎01-22-2013
My Device: 9900
My Carrier: GiffGaff

Re: Getting PEM key to form an instance of RSA Public key

hi there, did you manage to find a solution for this? if yes. please could you share your experience