79 Key aesKey = jwe.getKeyStorage().getCEKKey(JWEKeyStorage.KeyUse.ENCRYPTION,
false);
81 throw new IllegalArgumentException(
"AES CEK key not present");
84 Key hmacShaKey = jwe.getKeyStorage().getCEKKey(JWEKeyStorage.KeyUse.SIGNATURE,
false);
85 if (hmacShaKey == null) {
86 throw new IllegalArgumentException(
"HMAC CEK key not present");
90 if (expectedAesKeyLength != aesKey.getEncoded().length) {
91 throw new IllegalStateException(
"Length of aes key should be " + expectedAesKeyLength +
", but was " + aesKey.getEncoded().length);
94 byte[] aad = jwe.getBase64Header().getBytes(
"UTF-8");
95 byte[] authenticationTag =
computeAuthenticationTag(aad, jwe.getInitializationVector(), jwe.getEncryptedContent(), hmacShaKey);
97 byte[] expectedAuthTag = jwe.getAuthenticationTag();
98 boolean digitsEqual = MessageDigest.isEqual(expectedAuthTag, authenticationTag);
101 throw new IllegalArgumentException(
"Signature validations failed");
104 byte[] contentBytes =
decryptBytes(jwe.getEncryptedContent(), jwe.getInitializationVector(), aesKey);
106 jwe.content(contentBytes);
abstract int getExpectedAesKeyLength()
byte [] computeAuthenticationTag(byte[] aadBytes, byte[] ivBytes, byte[] cipherBytes, Key hmacKeySpec)
Definition: AesCbcHmacShaEncryptionProvider.java:133
byte [] decryptBytes(byte[] encryptedBytes, byte[] ivBytes, Key aesKey)
Definition: AesCbcHmacShaEncryptionProvider.java:125