September 15, 2016

Java Supported Cipher (Encryption) Algorithms

Reference : https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher

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: