@nfen/webcrypto-ts
Version:
Enforced Webcrypto wrapper
48 lines • 2.07 kB
JavaScript
/**
* Shared code for AES
* @module
*/
import * as usages from "../key_usages.js";
import * as WebCrypto from "../webcrypto.js";
export var Alg;
(function (Alg) {
let Mode;
(function (Mode) {
Mode["AES_CBC"] = "AES-CBC";
Mode["AES_CTR"] = "AES-CTR";
Mode["AES_GCM"] = "AES-GCM";
Mode["AES_KW"] = "AES-KW";
})(Mode = Alg.Mode || (Alg.Mode = {}));
})(Alg || (Alg = {}));
export var AesShared;
(function (AesShared) {
async function generateKey(algorithm, extractable = true, keyUsages) {
return await WebCrypto.generateKey(algorithm, extractable, keyUsages ?? usages.getKeyUsagePairsByAlg(algorithm.name));
}
AesShared.generateKey = generateKey;
async function importKey(format, key, algorithm, extractable = true, keyUsages) {
return await WebCrypto.importKey(format, key, algorithm, extractable, keyUsages ?? usages.getKeyUsagePairsByAlg(algorithm.name));
}
AesShared.importKey = importKey;
async function exportKey(format, key) {
return await WebCrypto.exportKey(format, key);
}
AesShared.exportKey = exportKey;
async function encrypt(algorithm, key, data) {
return await WebCrypto.encrypt(algorithm, key, data);
}
AesShared.encrypt = encrypt;
async function decrypt(algorithm, key, data) {
return await WebCrypto.decrypt(algorithm, key, data);
}
AesShared.decrypt = decrypt;
async function wrapKey(format, key, wrappingkey, wrapAlgorithm) {
return await WebCrypto.wrapKey(format, key, wrappingkey, wrapAlgorithm);
}
AesShared.wrapKey = wrapKey;
async function unwrapKey(format, wrappedKey, wrappedKeyAlgorithm, unwrappingKey, unwrappingKeyAlgorithm, extractable = true, keyUsages) {
return await WebCrypto.unwrapKey(format, wrappedKey, unwrappingKey, unwrappingKeyAlgorithm, wrappedKeyAlgorithm, extractable, keyUsages ?? usages.getKeyUsagePairsByAlg(wrappedKeyAlgorithm.name));
}
AesShared.unwrapKey = unwrapKey;
})(AesShared || (AesShared = {}));
//# sourceMappingURL=shared.js.map