Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 2.21 KB

jwe_flattened_decrypt.flattenedDecrypt.md

File metadata and controls

61 lines (46 loc) · 2.21 KB

Function: flattenedDecrypt

jwe/flattened/decrypt.flattenedDecrypt

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

Decrypts a Flattened JWE.

example ESM import

import { flattenedDecrypt } from 'jose/jwe/flattened/decrypt'

example CJS import

const { flattenedDecrypt } = require('jose/jwe/flattened/decrypt')

example Deno import

import { flattenedDecrypt } from 'https://deno.land/x/jose@v3.18.0/jwe/flattened/decrypt.ts'

example Usage

const decoder = new TextDecoder()
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 flattenedDecrypt(jwe, privateKey)

console.log(protectedHeader)
console.log(decoder.decode(plaintext))
console.log(decoder.decode(additionalAuthenticatedData))

Parameters

Name Type Description
jwe FlattenedJWE Flattened JWE.
key KeyLike | FlattenedDecryptGetKey Public Key or Secret, or a function resolving one, to decrypt the JWE with.
options? DecryptOptions JWE Decryption options.

Returns

Promise<FlattenedDecryptResult>

Defined in

jwe/flattened/decrypt.ts:80