Java 256-bit AES Password-Based Encryption

后端 未结 9 1371
名媛妹妹
名媛妹妹 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:40

    Consider using Encryptor4j of which I am the author.

    First make sure you have Unlimited Strength Jurisdiction Policy files installed before your proceed so that you can use 256-bit AES keys.

    Then do the following:

    String password = "mysupersecretpassword"; 
    Key key = KeyFactory.AES.keyFromPassword(password.toCharArray());
    Encryptor encryptor = new Encryptor(key, "AES/CBC/PKCS7Padding", 16);
    

    You can now use the encryptor to encrypt your message. You can also perform streaming encryption if you'd like. It automatically generates and prepends a secure IV for your convenience.

    If it's a file that you wish to compress take a look at this answer Encrypting a large file with AES using JAVA for an even simpler approach.

提交回复
热议问题