|
在4.2系统中,KeyGenerator每次生成的key都不一样,同样的代码在4.1一下就没有问题,这是为什么?升级到4.2后,加密的东西就无法解密了
代码如下:
String seed = "1234567890ABCDEF";
KeyGenerator kgen;
try {
kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed.getBytes());
kgen.init(128, sr);
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
String str = "";
for(int i = 0; i < raw.length; i++) {
str = str + raw[i] + ",";
}
Log.d("CharacterAESCrypt", str);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
|
|