initial commit
This commit is contained in:
27
server/node_modules/jose/dist/node/esm/jwe/compact/decrypt.js
generated
vendored
Normal file
27
server/node_modules/jose/dist/node/esm/jwe/compact/decrypt.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { flattenedDecrypt } from '../flattened/decrypt.js';
|
||||
import { JWEInvalid } from '../../util/errors.js';
|
||||
import { decoder } from '../../lib/buffer_utils.js';
|
||||
export async function compactDecrypt(jwe, key, options) {
|
||||
if (jwe instanceof Uint8Array) {
|
||||
jwe = decoder.decode(jwe);
|
||||
}
|
||||
if (typeof jwe !== 'string') {
|
||||
throw new JWEInvalid('Compact JWE must be a string or Uint8Array');
|
||||
}
|
||||
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag, length, } = jwe.split('.');
|
||||
if (length !== 5) {
|
||||
throw new JWEInvalid('Invalid Compact JWE');
|
||||
}
|
||||
const decrypted = await flattenedDecrypt({
|
||||
ciphertext,
|
||||
iv: (iv || undefined),
|
||||
protected: protectedHeader || undefined,
|
||||
tag: (tag || undefined),
|
||||
encrypted_key: encryptedKey || undefined,
|
||||
}, key, options);
|
||||
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
||||
if (typeof key === 'function') {
|
||||
return { ...result, key: decrypted.key };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
26
server/node_modules/jose/dist/node/esm/jwe/compact/encrypt.js
generated
vendored
Normal file
26
server/node_modules/jose/dist/node/esm/jwe/compact/encrypt.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { FlattenedEncrypt } from '../flattened/encrypt.js';
|
||||
export class CompactEncrypt {
|
||||
constructor(plaintext) {
|
||||
this._flattened = new FlattenedEncrypt(plaintext);
|
||||
}
|
||||
setContentEncryptionKey(cek) {
|
||||
this._flattened.setContentEncryptionKey(cek);
|
||||
return this;
|
||||
}
|
||||
setInitializationVector(iv) {
|
||||
this._flattened.setInitializationVector(iv);
|
||||
return this;
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
this._flattened.setProtectedHeader(protectedHeader);
|
||||
return this;
|
||||
}
|
||||
setKeyManagementParameters(parameters) {
|
||||
this._flattened.setKeyManagementParameters(parameters);
|
||||
return this;
|
||||
}
|
||||
async encrypt(key, options) {
|
||||
const jwe = await this._flattened.encrypt(key, options);
|
||||
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user