this example中使用了已定义的密钥:
byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
我需要知道生成动态增强的不可预测密钥的推荐方法是什么,尤其是在使用JAX-WS,JAX-RS Web服务的安全性时。
答案 0 :(得分:1)
这就是Java中SecureRandom
类的用途:
SecureRandom random = new SecureRandom();
byte[] key = new byte[24]; // 24 or whatever your key length is
random.nextBytes(key);
根据Javadoc文档,SecureRandom提供了“加密强随机数生成器(RNG)”。 它经常因为速度缓慢而受到指责,但不是因为不安全。