我有一段代码,我用 AES 密钥包装我的对称密钥(AES):
- swkKey:这是用于包装的 AES 密钥。
- key:要包装的密钥。
代码:
SecretKey swkKeySpec = new SecretKeySpec(swkKey, 0, swkKey.length, "AES");
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
final int ivLength = 12;
final IvParameterSpec iv = createIV(ivLength);///Creates a new array.
cipher.init(Cipher.WRAP_MODE, swkKeySpec, iv);
SecretKey sKeySpec = new SecretKeySpec(key, 0, key.length, "AES");
byte[] wrappedAppKey = cipher.wrap(sKeySpec);`
如果 key 是 256 位而 swkkey 是 256 位,则 WrappedAppKey 的长度是多少。包装的密钥可以超过 32 个字节吗?请注意,在这种情况下,我会收到以下日志:
key length: 32(key to be wrapped)
swkKey length: 32(key used to wrap)
wrappedAppKey size: 48(final wrapped key output).