openssl 加盐_用盐打开Openssl AES 256 CBC Java Decrypt文件

我已经尝试了几天用java解密用openssl加密的消息 . 使用以下命令加密消息:

openssl enc -e -aes-256-cbc -kfile $ file.key -in toto -out toto.enc .

文件file.key包含256位的对称密钥 . 在命令中没有指定salt,但文件以Salted__开头 . 这是我编写的类,试图解密该文件,但即使删除该文件的16个字符即可获取任何内容,即:Salted__ salt加密 . 我得到错误:线程“main”中的异常javax.crypto.BadPaddingException:给定最终块未正确填充 .

有人能帮助我吗?

非常感谢你 .

public class Java {

private static SecretKey key = null;

private static Cipher cipher = null;

public static void main(String[] args) throws Exception

{

String filename = RESOURCES_DIR + "toto.enc";

byte[] key = Base64.decode("2AxIw+/AzDBj83OILV9GDpOs+izDFJEhD6pve/IPsN9=");

SecretKeySpec secretKey = new SecretKeySpec(key, "AES");

cipher = Cipher.getInstance("AES");

cipher.init(Cipher.DECRYPT_MODE, secretKey);

byte[] test = Base64.decode(readFile(filename));

byte[] decryptedBytes = cipher.doFinal(test);

String decryptedText = new String(decryptedBytes, "UTF8");

System.out.println("After decryption: " + decryptedText);

}

public final static String RESOURCES_DIR = "C:/Users/toto/Desktop/";

static String readFile(String filename) throws FileNotFoundException, IOException {

FileReader fr;

BufferedReader br;

fr = new FileReader(new File(filename));

br = new BufferedReader(fr);

String str;

String res = "";

while ((str = br.readLine()) != null) {

res += str;

}

return res;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值