Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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