js-crypto-key-utils
Version:
Universal Module for Cryptographic Key Utilities in JavaScript, including PEM-JWK converters
175 lines • 6.25 kB
JavaScript
"use strict";
/**
* asn1def.js
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PBES2ESParams = exports.PBKDF2Params = exports.PBES2Params = exports.PBEParameter = exports.EncryptedPrivateKeyInfo = exports.OneAsymmetricKey = exports.SubjectPublicKeyInfo = exports.KeyStructure = void 0;
var asn1_js_1 = __importDefault(require("asn1.js"));
///////////////////////////////////////////////////////////////////////////////////////////
/**
* This is either one of subjectPublicKeyInfo, oneAsymmetricKey or encryptedPrivateKeyInfo in ASN.1 format.
* @type {AsnObject}
*/
exports.KeyStructure = asn1_js_1.default.define('KeyStructure', function () {
// @ts-ignore
this.choice({
// @ts-ignore
subjectPublicKeyInfo: this.use(exports.SubjectPublicKeyInfo),
// @ts-ignore
oneAsymmetricKey: this.use(exports.OneAsymmetricKey),
// @ts-ignore
encryptedPrivateKeyInfo: this.use(exports.EncryptedPrivateKeyInfo)
});
});
/**
* SubjectPublicKeyInfo specified in RFC 5280 {@link https://tools.ietf.org/html/rfc5280}.
* @type {AsnObject}
*/
exports.SubjectPublicKeyInfo = asn1_js_1.default.define('SubjectPublicKeyInfo', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('algorithm').use(AlgorithmIdentifier),
// @ts-ignore
this.key('subjectPublicKey').bitstr());
});
///////////////////////////////////////////////////////////////////////////////////////////
/**
* OneAsymmetricKey specified in RFC5958 {@link https://tools.ietf.org/html/rfc5958}.
* (old version PrivateKeyInfo {@link https://tools.ietf.org/html/rfc5208}.)
* @type {AsnObject}
*/
exports.OneAsymmetricKey = asn1_js_1.default.define('OneAsymmetricKey', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('version').use(Version),
// @ts-ignore
this.key('privateKeyAlgorithm').use(AlgorithmIdentifier),
// @ts-ignore
this.key('privateKey').octstr(),
// @ts-ignore
this.key('attributes').implicit(0).optional().any(),
// @ts-ignore
this.key('publicKey').implicit(1).optional().bitstr());
});
/**
* EncryptedPrivateKeyInfo specified in RFC5958 {@link https://tools.ietf.org/html/rfc5958}.
* @type {AsnObject}
*/
exports.EncryptedPrivateKeyInfo = asn1_js_1.default.define('EncryptedPrivateKeyInfo', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('encryptionAlgorithm').use(AlgorithmIdentifier),
// @ts-ignore
this.key('encryptedData').octstr());
});
///////////////////////////////////////////////////////////////////////////////////////////
/**
* PBEParameter, parameter for password-based encryption, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}.
* @type {AsnObject}
*/
exports.PBEParameter = asn1_js_1.default.define('PBEParameter', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('salt').octstr(8),
// @ts-ignore
this.key('iterationCount').int());
});
/**
* PBES2Params, parameter for password-based encryption scheme 2, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}.
* @type {AsnObject}
*/
exports.PBES2Params = asn1_js_1.default.define('PBES2Params', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('keyDerivationFunc').use(AlgorithmIdentifier),
// @ts-ignore
this.key('encryptionScheme').use(AlgorithmIdentifier));
});
///////////////////////////////////////////////////////////////////////////////////////////
// PBKDF2-params ::= SEQUENCE {
// salt CHOICE {
// specified OCTET STRING,
// otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
// },
// iterationCount INTEGER (1..MAX),
// keyLength INTEGER (1..MAX) OPTIONAL,
// prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
// algid-hmacWithSHA1
// }
/**
* PBKDF2Params, parameter for PBKDF2, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}.
* @type {AsnObject}
*/
exports.PBKDF2Params = asn1_js_1.default.define('PBKDF2Params', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('salt').choice({
// @ts-ignore
'specified': this.octstr(),
// @ts-ignore
'otherSource': this.use(AlgorithmIdentifier)
}),
// @ts-ignore
this.key('iterationCount').int(),
// @ts-ignore
this.key('keyLength').int().optional(),
// @ts-ignore
this.key('prf').use(AlgorithmIdentifier).def({
algorithm: [1, 2, 840, 113549, 2, 7],
parameters: Buffer.from([0x05, 0x00])
}));
});
///////////////////////////////////////////////////////////////////////////////////////////
/**
* PBES2ESParams specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}.
* @type {{'aes192-cbc': AsnObject, 'aes128-cbc': AsnObject, 'des-ede3-cbc': Object, 'aes256-cbc': AsnObject}}
*/
exports.PBES2ESParams = {
'des-ede3-cbc': asn1_js_1.default.define('DesEde3CbcParams', function () {
// @ts-ignore
this.octstr();
}),
'aes128-cbc': asn1_js_1.default.define('Aes128CbcParams', function () {
// @ts-ignore
this.octstr();
}),
'aes192-cbc': asn1_js_1.default.define('Aes192CbcParams', function () {
// @ts-ignore
this.octstr();
}),
'aes256-cbc': asn1_js_1.default.define('Aes256CbcParams', function () {
// @ts-ignore
this.octstr();
})
};
////////////////////////////////////////////////////////////////////////////////////
/**
* AlgorithmIdentifier given in RFC 5280 {@link https://tools.ietf.org/html/rfc5280}
* @type AsnObject
*/
var AlgorithmIdentifier = asn1_js_1.default.define('AlgorithmIdentifier', function () {
// @ts-ignore
this.seq().obj(
// @ts-ignore
this.key('algorithm').objid(),
// @ts-ignore
this.key('parameters').optional().any());
});
/**
* Version
* @type {AsnObject}
*/
var Version = asn1_js_1.default.define('Version', function () {
// @ts-ignore
this.int();
});
//# sourceMappingURL=asn1def.js.map