升级到1.45的时候BouncyCastle的AES错误 [英] BouncyCastle AES error when upgrading to 1.45

查看:280
本文介绍了升级到1.45的时候BouncyCastle的AES错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近升级了从公元前1.34至1.45。我解码一些$ P $有以下pviously恩codeD数据:

Recently upgraded from BC 1.34 to 1.45. I'm decoding some previously-encoded data with the following:

    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    byte[] decrypted = cipher.doFinal(encrypted);

在使用BC 1.45我得到这个异​​常:

When using BC 1.45 I get this exception:

javax.crypto.BadPaddingException: pad block corrupted
 at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:715)
 at javax.crypto.Cipher.doFinal(Cipher.java:1090)

编辑:更多关于这个问题的。我使用下面的产生从密码的原始密钥:

More about this issue. I am using the following to generate raw keys from a passphrase:

    KeyGenerator kgen = KeyGenerator.getInstance("AES", "BC");
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
    sr.setSeed(seed);
    kgen.init(128, sr);
    SecretKey skey = kgen.generateKey();
    byte[] raw = skey.getEncoded();

我所发现的是,这会导致对BC 1.34两个不同的值VS 1.45。

What I have found is that this results in two different values for BC 1.34 vs 1.45.

这也可能不是BouncyCastle的相关的(我测试的是Android 2.3)

It might also not be BouncyCastle-related (I am testing on Android 2.3)

推荐答案

看起来问题SecureRandom的不是整个升级Froyo,姜饼边界便携。这篇文章描述了一个类似的问题:

Looks like the problem is SecureRandom not being portable across the Froyo-Gingerbread boundary. This post describes a similar problem:

http://groups.google.com/group/android-security-discuss/browse_thread/thread/6ec015a33784b925

我不知道在SecureRandom的完全变了,但我发现修复它的唯一方法是重新加密使用的是便携式方法生成的钥匙中的数据。

I am not sure what exactly changed in SecureRandom, but the only way I found to fix it was to reencrypt the data with keys generated using a portable method.

这篇关于升级到1.45的时候BouncyCastle的AES错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆