Java 256-bit AES Password-Based Encryption

后端 未结 9 1407
名媛妹妹
名媛妹妹 2020-11-21 05:22

I need to implement 256 bit AES encryption, but all the examples I have found online use a \"KeyGenerator\" to generate a 256 bit key, but I would like to use my own passkey

9条回答
  •  眼角桃花
    2020-11-21 05:51

    (Maybe helpful for others with a similar requirement)

    I had a similar requirement to use AES-256-CBC encrypt and decrypt in Java.

    To achieve (or specify) the 256-byte encryption/decryption, Java Cryptography Extension (JCE) policy should set to "Unlimited"

    It can be set in the java.security file under $JAVA_HOME/jre/lib/security (for JDK) or $JAVA_HOME/lib/security (for JRE)

    crypto.policy=unlimited

    Or in the code as

    Security.setProperty("crypto.policy", "unlimited");
    

    Java 9 and later versions have this enabled by default.

提交回复
热议问题