Back to Jose

Function: flattenedDecrypt()

docs/jwe/flattened/decrypt/functions/flattenedDecrypt.md

6.2.96.1 KB
Original Source

Function: flattenedDecrypt()

šŸ’— Help the project

Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.

Call Signature

ā–ø flattenedDecrypt(jwe, key, options?): Promise<FlattenedDecryptResult>

Decrypts a Flattened JWE.

This function is exported (as a named export) from the main 'jose' module entry point as well as from its subpath export 'jose/jwe/flattened/decrypt'.

Parameters

ParameterTypeDescription
jweFlattenedJWEFlattened JWE.
keyKeyInputPrivate Key or Secret to decrypt the JWE with. See Algorithm Key Requirements.
options?DecryptOptionsJWE Decryption options.

Returns

Promise<FlattenedDecryptResult>

Example

js
const jwe = {
  ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
  iv: '8Fy7A_IuoX5VXG9s',
  tag: 'W76IYV6arGRuDSaSyWrQNg',
  encrypted_key:
    'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA',
  aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
  protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0',
}

const { plaintext, protectedHeader, additionalAuthenticatedData } =
  await jose.flattenedDecrypt(jwe, privateKey)

console.log(protectedHeader)
const decoder = new TextDecoder()
console.log(decoder.decode(plaintext))
console.log(decoder.decode(additionalAuthenticatedData))

Call Signature

ā–ø flattenedDecrypt<KeyType>(jwe, getKey, options?): Promise<FlattenedDecryptResult & ResolvedKey<KeyType>>

Decrypts a Flattened JWE, resolving the key dynamically. The result additionally carries the resolved key.

Type Parameters

Type ParameterDefault type
KeyType extends Uint8Array | CryptoKeyUint8Array | CryptoKey

Parameters

ParameterTypeDescription
jweFlattenedJWEFlattened JWE.
getKeyFlattenedDecryptGetKey<KeyType>Function resolving Private Key or Secret to decrypt the JWE with. See Algorithm Key Requirements.
options?DecryptOptionsJWE Decryption options.

Returns

Promise<FlattenedDecryptResult & ResolvedKey<KeyType>>

Call Signature

ā–ø flattenedDecrypt(jwe, key, options?): Promise<FlattenedDecryptResult & Partial<ResolvedKey<Uint8Array | CryptoKey>>>

Accepts either form of the key argument. Use this overload when forwarding a value that may be either a key or a key resolution function; key is present on the result only when a resolution function was used.

Parameters

ParameterTypeDescription
jweFlattenedJWEFlattened JWE.
keyKeyInput | FlattenedDecryptGetKey<Uint8Array | CryptoKey>Private Key or Secret, or a function resolving one, to decrypt the JWE with. See Algorithm Key Requirements.
options?DecryptOptionsJWE Decryption options.

Returns

Promise<FlattenedDecryptResult & Partial<ResolvedKey<Uint8Array | CryptoKey>>>