Aerogear in Java and Creating Cyptobox using PublicKey

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Aerogear in Java and Creating Cyptobox using PublicKey

niteshdev
Hi There,

We are integrating aerogear java library in our java backend.

We have list of users public key in base64 string. Now when I want to send a encrypted message to our users.

When we are trying to create a instance of CryptoBox then at that time we need to provide a instance of PublicKey. How do we create a publickey Instance from a base64 string or raw bytes.

CryptoBox pandora = new CryptoBox(myprivatekey, userspublickey);

For the normal RSA i found this snippet over internet but i am assuming that this has to be different for Aerogear.
public static PublicKey loadPublicKey(String stored) throws GeneralSecurityException {
                byte[] data = Base64.decode(stored.toCharArray());
                X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
                KeyFactory fact = KeyFactory.getInstance("RSA");
                return fact.generatePublic(spec);
        }

Any help in this regard is highly appreciated.

Many Thanks,
Nitesh