UNPKG

js-crypto-key-utils

Version:

Universal Module for Cryptographic Key Utilities in JavaScript, including PEM-JWK converters

72 lines 3.33 kB
"use strict"; /** * params.ts */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getAlgorithmFromOidStrict = exports.getAlgorithmFromOid = exports.hashes = exports.encryptionSchemes = exports.pbkdf2Prfs = exports.keyDerivationFunctions = exports.passwordBasedEncryptionSchemes = exports.publicKeyAlgorithms = exports.namedCurves = void 0; // oid is referred to rfc5480 https://www.ietf.org/rfc/rfc5480.txt exports.namedCurves = { 'P-256': { indutnyName: 'p256', payloadSize: 32, oid: [1, 2, 840, 10045, 3, 1, 7] }, 'P-384': { indutnyName: 'p384', payloadSize: 48, oid: [1, 3, 132, 0, 34] }, 'P-521': { indutnyName: 'p521', payloadSize: 66, oid: [1, 3, 132, 0, 35] }, 'P-256K': { indutnyName: 'secp256k1', payloadSize: 32, oid: [1, 3, 132, 0, 10] }, }; // https://tools.ietf.org/html/rfc3279 exports.publicKeyAlgorithms = { 'EC': { oid: [1, 2, 840, 10045, 2, 1] }, 'RSA': { oid: [1, 2, 840, 113549, 1, 1, 1] } }; exports.passwordBasedEncryptionSchemes = { // PBES1 'pbeWithMD5AndDES-CBC': { oid: [1, 2, 840, 113549, 1, 5, 3], hash: 'MD5', encrypt: 'DES-CBC' }, 'pbeWithSHA1AndDES-CBC': { oid: [1, 2, 840, 113549, 1, 5, 10], hash: 'SHA-1', encrypt: 'DES-CBC' }, // PBES2 'pbes2': { oid: [1, 2, 840, 113549, 1, 5, 13] } }; exports.keyDerivationFunctions = { 'pbkdf2': { oid: [1, 2, 840, 113549, 1, 5, 12], defaultSaltLen: 8 } }; exports.pbkdf2Prfs = { 'hmacWithSHA1': { oid: [1, 2, 840, 113549, 2, 7], hash: 'SHA-1' }, 'hmacWithSHA256': { oid: [1, 2, 840, 113549, 2, 9], hash: 'SHA-256' }, 'hmacWithSHA384': { oid: [1, 2, 840, 113549, 2, 10], hash: 'SHA-384' }, 'hmacWithSHA512': { oid: [1, 2, 840, 113549, 2, 11], hash: 'SHA-512' } }; exports.encryptionSchemes = { 'des-ede3-cbc': { oid: [1, 2, 840, 113549, 3, 7], keyLength: 24, ivLength: 8 }, 'aes128-cbc': { oid: [2, 16, 840, 1, 101, 3, 4, 1, 2], keyLength: 16, ivLength: 16 }, 'aes192-cbc': { oid: [2, 16, 840, 1, 101, 3, 4, 1, 22], keyLength: 24, ivLength: 16 }, 'aes256-cbc': { oid: [2, 16, 840, 1, 101, 3, 4, 1, 42], keyLength: 32, ivLength: 16 } }; exports.hashes = { 'SHA-256': { hashSize: 32 }, 'SHA-384': { hashSize: 48 }, 'SHA-512': { hashSize: 64 }, 'SHA-1': { hashSize: 20 }, 'MD5': { hashSize: 16 } // SHOULD NOT USE }; /** * Get algorithm name from ObjectIdentifier array loosely. * @param {Array<number>} oid - ObjectIdentifier. * @param {Object} oidDict - Dictionary of ObjectIdentifier. * @return {Array} - Array of ObjectIdentifier array. */ function getAlgorithmFromOid(oid, oidDict) { return Object.keys(oidDict).filter(function (k) { return oidDict[k].oid.toString() === oid.toString(); }); } exports.getAlgorithmFromOid = getAlgorithmFromOid; /** * Get algorithm name from ObjectIdentifier array strictly. * @param {Array<number>} oid - ObjectIdentifier. * @param {Object} dict - Dictionary of ObjectIdentifier. * @return {Array} - Exactly one ObjectIdentifier. * @throws {Error} - Throws if UnsupportedAlgorithm. */ var getAlgorithmFromOidStrict = function (oid, dict) { var array = getAlgorithmFromOid(oid, dict); if (array.length === 0) throw new Error('UnsupportedAlgorithm'); return array[0]; }; exports.getAlgorithmFromOidStrict = getAlgorithmFromOidStrict; //# sourceMappingURL=params.js.map