我想加密然后解密文件使用AES.我读过很多关于错误的话题"Given final block not properly padded".但我没有为我找到解决方案.
抱歉指定我的代码语言,我不懂java语言
这是我的代码:
变量
// IV, secret, salt in the same time
private byte[] salt = { 'h', 'u', 'n', 'g', 'd', 'h', '9', '4' };
public byte[] iv;
public SecretKey secret;
Run Code Online (Sandbox Code Playgroud)
createSecretKey
public void createSecretKey(String password){
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 256);
SecretKey tmp = factory.generateSecret(spec);
secret = new SecretKeySpec(tmp.getEncoded(), "AES");
}
Run Code Online (Sandbox Code Playgroud)
方法加密
public void encrypt(String inputFile){
FileInputStream fis = new FileInputStream(inputFile);
// Save file: inputFile.enc …Run Code Online (Sandbox Code Playgroud)