Java Code Example:
public byte[] encrypt(PublicKey publicKey, String data) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
cipher.update(data.getBytes("UTF-8"));
return cipher.doFinal();
}
No comments:
Post a Comment