From 3bb7463416cb27debdad72faf3432c504987481d Mon Sep 17 00:00:00 2001 From: Kenta Long Yamamoto Date: Sat, 3 Jul 2021 04:45:01 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#53788=20node-jose:?= =?UTF-8?q?=20added=20iv=20option=20to=20JWE.createEncrypt=20by=20@ymkjp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * node-jose: added iv option to JWE.createEncrypt * node-jose: added string along with Buffer for iv option * Update types/node-jose/index.d.ts Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) --- types/node-jose/index.d.ts | 1 + types/node-jose/node-jose-tests.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/types/node-jose/index.d.ts b/types/node-jose/index.d.ts index cffac47a1714ae..6ac6d9bbce8e8c 100644 --- a/types/node-jose/index.d.ts +++ b/types/node-jose/index.d.ts @@ -97,6 +97,7 @@ export namespace JWE { fields?: object; contentAlg?: string; protect?: string | string[]; + iv?: string | Buffer; } function createEncrypt(keys: JWK.Key | JWK.Key[]): Encryptor; diff --git a/types/node-jose/node-jose-tests.ts b/types/node-jose/node-jose-tests.ts index 1917df00a5991c..df18f6b5551e70 100644 --- a/types/node-jose/node-jose-tests.ts +++ b/types/node-jose/node-jose-tests.ts @@ -1,4 +1,5 @@ import * as jose from 'node-jose'; +import * as crypto from "crypto"; const keystore = jose.JWK.createKeyStore(); const output = keystore.toJSON(); @@ -209,6 +210,20 @@ jose.JWK.createKey('oct', 256, { alg: 'A256GCM' }).then(result => { // .... }); + jose.JWE.createEncrypt({ iv: Buffer.alloc(96 / 8).toString('base64') }, key) + .update('input') + .final() + .then(result => { + // .... + }); + + jose.JWE.createEncrypt({iv: crypto.randomBytes(96 / 8) }, key) + .update('input') + .final() + .then(result => { + // .... + }); + jose.JWE.createEncrypt([key, key]) .update('input') .final()