129 int keyLength = aesKey.getEncoded().length;
132 case 16: encAlgorithm = JWEConstants.A128CBC_HS256;
134 case 24: encAlgorithm = JWEConstants.A192CBC_HS384;
136 case 32: encAlgorithm = JWEConstants.A256CBC_HS512;
138 default:
throw new IllegalArgumentException(
"Bad size for Encryption key: " + aesKey +
". Valid sizes are 16, 24, 32.");
142 byte[] contentBytes = JsonSerialization.writeValueAsBytes(jwt);
144 JWEHeader jweHeader =
new JWEHeader(JWEConstants.DIR, encAlgorithm, null);
147 .content(contentBytes);
150 .setCEKKey(aesKey, JWEKeyStorage.KeyUse.ENCRYPTION)
151 .setCEKKey(hmacKey, JWEKeyStorage.KeyUse.SIGNATURE);
153 return jwe.encodeJwe();
154 }
catch (IOException ioe) {
155 throw new JWEException(ioe);