How to encrypt a file in java using AES [duplicate

2019-02-06 11:16发布

问题:

This question already has an answer here:

  • Java 256-bit AES Password-Based Encryption 9 answers

I need to know how to create an AES and using it to encrypt and decrypt a file in java.

回答1:

Try using a CipherOutputStream and passing in a FileOutputStream. See http://www.java2s.com/Tutorial/Java/0490__Security/UsingCipherOutputStream.htm for a quick example, just use Cipher.getInstance("AES/CBC/PKCS5Padding") instead.