标签: cfb-mode

在python中加密并使用AES-CFB在Java中解密

我知道一个与此非常类似的问题(如何在Python中加密并在Java中解密?)但我有一个不同的问题.

我的问题是,我无法正确解密Java.尽管使用了正确的密钥和IV,我仍然在解密后获得垃圾字符.我在Java中没有任何编译/运行时错误或异常,因此我相信我正在使用正确的参数进行解密.

Python加密代码 -

from Crypto.Cipher import AES
import base64
key = '0123456789012345'
iv = 'RandomInitVector'
raw = 'samplePlainText'
cipher = AES.new(key,AES.MODE_CFB,iv)
encrypted = base64.b64encode(iv + cipher.encrypt(raw))
Run Code Online (Sandbox Code Playgroud)

Java解密代码 -

private static String KEY = "0123456789012345";
public static String decrypt(String encrypted_encoded_string) throws NoSuchAlgorithmException, NoSuchPaddingException,
    InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

      String plain_text = "";
      try{
          byte[] encrypted_decoded_bytes = Base64.getDecoder().decode(encrypted_encoded_string);
          String encrypted_decoded_string = new String(encrypted_decoded_bytes);
          String iv_string = encrypted_decoded_string.substring(0,16); //IV is retrieved correctly.

          IvParameterSpec iv = new IvParameterSpec(iv_string.getBytes());
          SecretKeySpec skeySpec = new …
Run Code Online (Sandbox Code Playgroud)

python java encryption pycrypto cfb-mode

4
推荐指数
1
解决办法
4046
查看次数

标签 统计

cfb-mode ×1

encryption ×1

java ×1

pycrypto ×1

python ×1