在java中加密数据时如下:
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key, sr);
// why the sr is necessary to init a Cipher object?
byte data[] = str.getBytes();
byte[] encryptedData = cipher.doFinal(data);
为什么需要 aSecureRandom
对象sr
来初始化 Cipher 对象?至于解密方面,也需要一个SecureRandom
与加密大小生成的对象不同的对象。这些SecureRandom
对象仅用于奇偶校验位吗?