Back to Jose

Function: compactDecrypt()

docs/jwe/compact/decrypt/functions/compactDecrypt.md

6.2.125.6 KB
Original Source

Function: compactDecrypt()

šŸ’— 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

ā–ø compactDecrypt(jwe, key, options?): Promise<CompactDecryptResult>

Decrypts a Compact 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/compact/decrypt'.

Parameters

ParameterTypeDescription
jwestring | Uint8ArrayCompact JWE.
keyKeyInputPrivate key or shared secret. See Algorithm Key Requirements.
options?DecryptOptionsJWE Decryption options.

Returns

Promise<CompactDecryptResult>

Example

js
const jwe =
  'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0.nyQ19eq9ogh9wA7fFtnI2oouzy5_8b5DeLkoRMfi2yijgfTs2zEnayCEofz_qhnL-nwszabd9qUeHv0-IwvhhJJS7GUJOU3ikiIe42qcIAFme1A_Fo9CTxw4XTOy-I5qanl8So91u6hwfyN1VxAqVLsSE7_23EC-gfGEg_5znew9PyXXsOIE-K_HH7IQowRrlZ1X_bM_Liu53RzDpLDvRz59mp3S8L56YqpM8FexFGTGpEaoTcEIst375qncYt3-79IVR7gZN1RWsWgjPatfvVbnh74PglQcATSf3UUhaW0OAKn6q7r3PDx6DIKQ35bgHQg5QopuN00eIfLQL2trGw.W3grIVj5HVuAb76X.6PcuDe5D6ttWFYyv0oqqdDXfI2R8wBg1F2Q80UUA_Gv8eEimNWfxIWdLxrjzgQGSvIhxmFKuLM0.a93_Ug3uZHuczj70Zavx8Q'

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

console.log(protectedHeader)
console.log(new TextDecoder().decode(plaintext))

Call Signature

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

Decrypts a Compact JWE with a dynamically resolved key, included in the result.

Type Parameters

Type ParameterDefault type
KeyType extends Uint8Array | CryptoKeyUint8Array | CryptoKey

Parameters

ParameterTypeDescription
jwestring | Uint8ArrayCompact JWE.
getKeyCompactDecryptGetKey<KeyType>Resolves a private key or shared secret from unverified token data.
options?DecryptOptionsJWE Decryption options.

Returns

Promise<CompactDecryptResult & ResolvedKey<KeyType>>

Call Signature

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

Decrypts a Compact JWE with a key or key resolver. The result includes key only when a resolver is used.

Parameters

ParameterTypeDescription
jwestring | Uint8ArrayCompact JWE.
keyKeyInput | CompactDecryptGetKey<Uint8Array | CryptoKey>Private key or shared secret, or a function resolving one.
options?DecryptOptionsJWE Decryption options.

Returns

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