List of usage examples for org.bouncycastle.util.encoders Base64 encode
public static byte[] encode(byte[] data, int off, int length)
From source file:emailsecurity.RSABouncyCastleKeyGeneration.java
public RSABouncyCastleKeyGeneration() throws IOException { fetchAccountDetails();/*from w w w . ja v a 2 s. c o m*/ File tempPublicKey = new File("public_keys" + File.separator + this.publicKeyFileName); File tempPrivateKey = new File("private_key" + File.separator + "id_rsa"); if (!tempPublicKey.exists() && !tempPrivateKey.exists()) { try { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(1024); KeyPair key = keyGen.generateKeyPair(); PrivateKey priv = key.getPrivate(); PublicKey pub = key.getPublic(); RSAPublicKey pubKey = (RSAPublicKey) key.getPublic(); RSAPrivateKey priKey = (RSAPrivateKey) key.getPrivate(); writeKeyFile(key, tempPublicKey, tempPrivateKey); String privateKey = new String(Base64.encode(priv.getEncoded(), 0, priv.getEncoded().length)); String publicKey1 = new String(Base64.encode(pub.getEncoded(), 0, pub.getEncoded().length)); String publicKey = new String( Base64.encode(publicKey1.getBytes(), 0, publicKey1.getBytes().length)); System.out.println("Public Key = " + publicKey1); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("Keys Exist"); } }