我正在尝试使用 SecureRandom 生成随机密钥,但是在将输出放入字节数组时遇到了问题。它无法识别 SecureRandom 的输出。
public static String byteToHex(byte[] hash) {
StringBuilder sb = new StringBuilder(hash.length * 2);
for(byte b: hash) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
SecureRandom r = new SecureRandom();
byte a[] = new byte[16];
r.nextBytes(a);
我将输出硬编码为字节数组:
byte[] k = {ac,1d,71,c8,96,bd,f7,d5,03,38,bc,46,a2,b4,f1,a8};
我得到的错误是:
Multiple markers at this line
- a2 cannot be resolved to a variable
- bd cannot be resolved to a variable
- d5 cannot be resolved to a variable
- b4 cannot be resolved to a variable
- c8 cannot be resolved to a variable
- f7 cannot be resolved to a variable
- a8 cannot be resolved to a variable
- f1 cannot be resolved to a variable
- Type mismatch: cannot convert from double
to byte
- ac cannot be resolved to a variable
- bc cannot be resolved to a variable
- Type mismatch: cannot convert from double
to byte
我想用它作为用 AES 加密消息的密钥