Skip to content

Instantly share code, notes, and snippets.

@NetworksAreMadeOfString
Created June 9, 2012 23:08
Show Gist options
  • Save NetworksAreMadeOfString/2902960 to your computer and use it in GitHub Desktop.
Save NetworksAreMadeOfString/2902960 to your computer and use it in GitHub Desktop.
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.decode(this.PrivateKey.getBytes(),0));
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey pk = kf.generatePrivate(spec);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
cipher.init(Cipher.ENCRYPT_MODE, pk);
byte[] EncryptedStream = new byte[cipher.getOutputSize(dataToSign.length())];
try
{
cipher.doFinal(dataToSign.getBytes(),0,dataToSign.length(), EncryptedStream,0);
}
catch (ShortBufferException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return Base64.encodeToString(EncryptedStream, Base64.NO_WRAP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment