Skip to content

Instantly share code, notes, and snippets.

@lkdocs
Created September 11, 2013 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkdocs/6526771 to your computer and use it in GitHub Desktop.
Save lkdocs/6526771 to your computer and use it in GitHub Desktop.
private byte[] encryptWithPublicKey(byte[] message, String publicKey) throws Exception {
String strippedKey = Crypto.stripPublicKeyHeaders(publicKey);
PublicKey apiPublicKey= Crypto.getRSAPublicKeyFromString(strippedKey);
Cipher rsaCipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding", "SC");
rsaCipher.init(Cipher.ENCRYPT_MODE, apiPublicKey);
return rsaCipher.doFinal(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment