Created
June 9, 2012 23:08
-
-
Save NetworksAreMadeOfString/2902960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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