对于没有JCA(JCE)的环境,例如Java ME
,使用java.util.Random
生成密钥(或iv)字节是否可以?
// MIDP
// MIDP
// MIDP
private static final Random RANDOM = new Random();
/**
* Generates a new encryption key. This method is not intended to be used in
* production stage.
*
* @return a new encryption key.
*/
protected static byte[] newKey() {
final Random random;
synchronized (RANDOM) {
random = new Random(RANDOM.nextLong());
}
final byte[] key = new byte[256]; // AES 256
for (int i = 0; i < key.length; i++) {
key[i] = (byte) random.nextInt(256);
}
return key;
}
是否有任何加密图形问题?
此问题中是否有任何拼写错误,包括源代码和注释? (我在Uslish不擅长。)