不使用KeyGenerator生成关键字节

时间:2012-11-02 03:52:18

标签: encryption jce jca

对于没有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不擅长。)

0 个答案:

没有答案