node-jose
node-jose copied to clipboard
Encrypt JWE content using preferred algorithm
I am trying to encrypt a SHA256 value using a wrap algorithm like PBES2-HS256+A128KW and encryption algorithm like A128GCM. The wrap algorithm is applied properly but noticed the encryption algorithm used is A128CBC-HS256.
When reading the provided documentation, I found this "If the Key supports key management algorithms, then the JWE content is encrypted using "A128CBC-HS256" by default, and the Content Encryption Key is encrypted using the preferred algorithms for the given Key. The preferred algorithm is the first item returned by key.algorithms("wrap")."
Is there a way to use the preferred algorithm for content encryption as well instead of the default
You can specify which content encryption algorithm to use when calling createEncrypt:
const opts = {
contentAlg: "A128GCM",
];
const jwe = jose.JWE.createEncrypt(opts, key);
...