How to use the asn1js.fromBER function in asn1js

To help you get started, we’ve selected a few asn1js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / pkijs / pkijs-tests.ts View on Github external
document.getElementById("cms-dgst-algos").innerHTML = "";

    document.getElementById("cms-certs").style.display = "none";
    document.getElementById("cms-crls").style.display = "none";

    const certificatesTable = document.getElementById("cms-certificates") as HTMLTableElement;
    while (certificatesTable.rows.length > 1)
        certificatesTable.deleteRow(certificatesTable.rows.length - 1);

    const crlsTable = document.getElementById("cms-rev-lists") as HTMLTableElement;
    while (crlsTable.rows.length > 1)
        crlsTable.deleteRow(crlsTable.rows.length - 1);
    // endregion

    // region Decode existing CMS Signed Data
    const asn1 = asn1js.fromBER(cmsSignedBuffer);
    const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
    const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
    // endregion

    // region Put information about digest algorithms in the CMS Signed Data
    const dgstmap: { [oid: string]: string } = {
        "1.3.14.3.2.26": "SHA-1",
        "2.16.840.1.101.3.4.2.1": "SHA-256",
        "2.16.840.1.101.3.4.2.2": "SHA-384",
        "2.16.840.1.101.3.4.2.3": "SHA-512"
    };

    for (let i = 0; i < cmsSignedSimpl.digestAlgorithms.length; i++) {
        let typeval = dgstmap[cmsSignedSimpl.digestAlgorithms[i].algorithmId];
        if (typeof typeval === "undefined")
            typeval = cmsSignedSimpl.digestAlgorithms[i].algorithmId;
github PeculiarVentures / PKI.js / examples / PKCS12SimpleExample / es6.js View on Github external
function passwordPrivacyInternal(password)
{
	//region Initial variables
	let sequence = Promise.resolve();
	
	const passwordConverted = stringToArrayBuffer(password);
	//endregion
	
	//region Create simplified structires for certificate and private key
	let asn1 = asn1js.fromBER(stringToArrayBuffer(fromBase64(certificateBASE64)));
	const certSimpl = new Certificate({ schema: asn1.result });
	
	asn1 = asn1js.fromBER(stringToArrayBuffer(fromBase64(privateKeyBASE64)));
	const pkcs8Simpl = new PrivateKeyInfo({ schema: asn1.result });
	//endregion
	
	//region Put initial values for PKCS#12 structures
	const pkcs12 = new PFX({
		parsedValue: {
			integrityMode: 0, // Password-Based Integrity Mode
			authenticatedSafe: new AuthenticatedSafe({
				parsedValue: {
					safeContents: [
						{
							privacyMode: 1, // Password-Based Privacy Protection Mode
							value: new SafeContents({
								safeBags: [
									new SafeBag({
										bagId: "1.2.840.113549.1.12.10.1.1",
github PeculiarVentures / PKI.js / src / Certificate.js View on Github external
toSchema(encodeFlag = false)
	{
		let tbsSchema = {};
		
		//region Decode stored TBS value
		if(encodeFlag === false)
		{
			if(this.tbs.length === 0) // No stored certificate TBS part
				return Certificate.schema().value[0];
			
			tbsSchema = asn1js.fromBER(this.tbs).result;
		}
		//endregion
		//region Create TBS schema via assembling from TBS parts
		else
			tbsSchema = this.encodeTBS();
		//endregion
		
		//region Construct and return new ASN.1 schema for this object
		return (new asn1js.Sequence({
			value: [
				tbsSchema,
				this.signatureAlgorithm.toSchema(),
				this.signatureValue
			]
		}));
		//endregion
github PeculiarVentures / PKI.js / src / RelativeDistinguishedNames.js View on Github external
toSchema()
	{
		//region Decode stored TBS value
		if(this.valueBeforeDecode.byteLength === 0) // No stored encoded array, create "from scratch"
		{
			return (new asn1js.Sequence({
				value: [new asn1js.Set({
					value: Array.from(this.typesAndValues, element => element.toSchema())
				})]
			}));
		}

		const asn1 = asn1js.fromBER(this.valueBeforeDecode);
		//endregion

		//region Construct and return new ASN.1 schema for this object
		return asn1.result;
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / examples / TSPResponseComplexExample / es6.js View on Github external
const accurTable = document.getElementById("resp-accuracy");
	while(accurTable.rows.length > 1)
		accurTable.deleteRow(accurTable.rows.length - 1);
	
	const tsTable = document.getElementById("resp-tsa");
	while(tsTable.rows.length > 1)
		tsTable.deleteRow(tsTable.rows.length - 1);
	
	const extTable = document.getElementById("resp-extensions");
	while(extTable.rows.length > 1)
		extTable.deleteRow(extTable.rows.length - 1);
	//endregion
	
	//region Decode existing TSP response
	const asn1 = asn1js.fromBER(tspResponseBuffer);
	const tspRespSimpl = new TimeStampResp({ schema: asn1.result });
	//endregion
	
	//region Put information about TSP response status
	let status = "";
	
	switch(tspRespSimpl.status.status)
	{
		case 0:
			status = "granted";
			break;
		case 1:
			status = "grantedWithMods";
			break;
		case 2:
			status = "rejection";
github PeculiarVentures / PKI.js / src / SignedCertificateTimestampList.js View on Github external
case 2:
					this.signatureAlgorithm = "dsa";
					break;
				case 3:
					this.signatureAlgorithm = "ecdsa";
					break;
				default:
					throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
			}
			//endregion
			
			//region Signature
			const signatureLength = stream.getUint16();
			const signatureData = (new Uint8Array(stream.getBlock(signatureLength))).buffer.slice(0);
			
			const asn1 = asn1js.fromBER(signatureData);
			if(asn1.offset === (-1))
				throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
			
			this.signature = asn1.result;
			//endregion
			
			if(blockLength !== (47 + extensionsLength + signatureLength))
				throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
		}
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / examples / CRLComplexExample / es6.js View on Github external
const revokedTable = document.getElementById("crl-rev-certs");
	while(revokedTable.rows.length > 1)
		revokedTable.deleteRow(revokedTable.rows.length - 1);
	
	const extensionTable = document.getElementById("crl-extn-table");
	while(extensionTable.rows.length > 1)
		extensionTable.deleteRow(extensionTable.rows.length - 1);
	
	const issuerTable = document.getElementById("crl-issuer-table");
	while(issuerTable.rows.length > 1)
		issuerTable.deleteRow(issuerTable.rows.length - 1);
	//endregion
	
	//region Decode existing CRL
	const asn1 = asn1js.fromBER(crlBuffer);
	const crlSimpl = new CertificateRevocationList({
		schema: asn1.result
	});
	//endregion
	
	//region Put information about CRL issuer
	const rdnmap = {
		"2.5.4.6": "C",
		"2.5.4.10": "O",
		"2.5.4.11": "OU",
		"2.5.4.3": "CN",
		"2.5.4.7": "L",
		"2.5.4.8": "S",
		"2.5.4.12": "T",
		"2.5.4.42": "GN",
		"2.5.4.43": "I",
github PeculiarVentures / PKI.js / examples / TSPRequestComplexExample / es6.js View on Github external
//endregion 
	
	//region Initial activities 
	document.getElementById("tsp-req-extn-div").style.display = "none";
	
	const imprintTable = document.getElementById("tsp-req-imprint");
	while(imprintTable.rows.length > 1)
		imprintTable.deleteRow(imprintTable.rows.length - 1);
	
	const extensionTable = document.getElementById("tsp-req-extn-table");
	while(extensionTable.rows.length > 1)
		extensionTable.deleteRow(extensionTable.rows.length - 1);
	//endregion
	
	//region Decode existing TSP request
	const asn1 = asn1js.fromBER(tspReqBuffer);
	const tspReqSimpl = new TimeStampReq({ schema: asn1.result });
	//endregion 
	
	//region Put information about message imprint 
	const dgstmap = {
		"1.3.14.3.2.26": "SHA-1",
		"2.16.840.1.101.3.4.2.1": "SHA-256",
		"2.16.840.1.101.3.4.2.2": "SHA-384",
		"2.16.840.1.101.3.4.2.3": "SHA-512"
	};
	
	let hashAlgorithm = dgstmap[tspReqSimpl.messageImprint.hashAlgorithm.algorithmId];
	if(typeof hashAlgorithm === "undefined")
		hashAlgorithm = tspReqSimpl.messageImprint.hashAlgorithm.algorithmId;
	
	const row = imprintTable.insertRow(imprintTable.rows.length);
github PeculiarVentures / PKI.js / src / PublicKeyInfo.js View on Github external
exportedKey =>
			{
				const asn1 = asn1js.fromBER(exportedKey);
				try
				{
					_this.fromSchema(asn1.result);
				}
				catch(exception)
				{
					return Promise.reject("Error during initializing object from schema");
				}
				
				return undefined;
			},
			error => Promise.reject(`Error during exporting public key: ${error}`)
github PeculiarVentures / PKI.js / examples / CertificateComplexExample / es6.js View on Github external
const issuerTable = document.getElementById("cert-issuer-table");
	while(issuerTable.rows.length > 1)
		issuerTable.deleteRow(issuerTable.rows.length - 1);
	
	const subjectTable = document.getElementById("cert-subject-table");
	while(subjectTable.rows.length > 1)
		subjectTable.deleteRow(subjectTable.rows.length - 1);
	
	const extensionTable = document.getElementById("cert-extn-table");
	while(extensionTable.rows.length > 1)
		extensionTable.deleteRow(extensionTable.rows.length - 1);
	//endregion
	
	//region Decode existing X.509 certificate
	const asn1 = asn1js.fromBER(certificateBuffer);
	const certificate = new Certificate({ schema: asn1.result });
	//endregion
	
	//region Put information about X.509 certificate issuer
	const rdnmap = {
		"2.5.4.6": "C",
		"2.5.4.10": "O",
		"2.5.4.11": "OU",
		"2.5.4.3": "CN",
		"2.5.4.7": "L",
		"2.5.4.8": "S",
		"2.5.4.12": "T",
		"2.5.4.42": "GN",
		"2.5.4.43": "I",
		"2.5.4.4": "SN",
		"1.2.840.113549.1.9.1": "E-mail"

asn1js

asn1js is a pure JavaScript library implementing this standard. ASN.1 is the basis of all X.509 related data structures and numerous other protocols used on the web

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

79 / 100
Full package analysis