How to use the asn1js.Integer 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 PeculiarVentures / PKI.js / examples / OCSPRequestComplexExample / es6.js View on Github external
const fictionBuffer = new ArrayBuffer(4);
	const fictionView = new Uint8Array(fictionBuffer);
	fictionView[0] = 0x7F;
	fictionView[1] = 0x01;
	fictionView[2] = 0x02;
	fictionView[3] = 0x03;
	
	ocspReqSimpl.tbsRequest.requestList = [new Request({
		reqCert: new CertID({
			hashAlgorithm: new AlgorithmIdentifier({
				algorithmId: "1.3.14.3.2.26"
			}),
			issuerNameHash: new asn1js.OctetString({ valueHex: fictionBuffer }),
			issuerKeyHash: new asn1js.OctetString({ valueHex: fictionBuffer }),
			serialNumber: new asn1js.Integer({ valueHex: fictionBuffer })
		})
	})];
	
	ocspReqSimpl.tbsRequest.requestExtensions = [
		new Extension({
			extnID: "1.3.6.1.5.5.7.48.1.2", // ocspNonce
			extnValue: (new asn1js.OctetString({ valueHex: fictionBuffer })).toBER(false)
		})
	];
	//endregion
	
	//region Encode OCSP request and put on the Web page
	ocspReqBuffer = ocspReqSimpl.toSchema(true).toBER(false);
	//endregion
	
	return Promise.resolve(true);
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificate(keyPair: CryptoKeyPair, caKey: CryptoKey) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: process.env.FORTIFY_SSL_CN || "fortifyapp.com" }),
  });

  certificate.subject.typesAndValues.push(commonName);
  certificate.issuer.typesAndValues.push(new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  }));

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
github PeculiarVentures / PKI.js / src / CertificateRevocationList.js View on Github external
* @type {Object}
	 * @property {string} [blockName]
	 * @property {string} [tbsCertListVersion]
	 * @property {string} [signature]
	 * @property {string} [issuer]
	 * @property {string} [tbsCertListThisUpdate]
	 * @property {string} [tbsCertListNextUpdate]
	 * @property {string} [tbsCertListRevokedCertificates]
	 * @property {string} [crlExtensions]
	 */
	const names = getParametersValue(parameters, "names", {});
	
	return (new asn1js.Sequence({
		name: (names.blockName || "tbsCertList"),
		value: [
			new asn1js.Integer({
				optional: true,
				name: (names.tbsCertListVersion || "tbsCertList.version"),
				value: 2
			}), // EXPLICIT integer value (v2)
			AlgorithmIdentifier.schema(names.signature || {
				names: {
					blockName: "tbsCertList.signature"
				}
			}),
			RelativeDistinguishedNames.schema(names.issuer || {
				names: {
					blockName: "tbsCertList.issuer"
				}
			}),
			Time.schema(names.tbsCertListThisUpdate || {
				names: {
github PeculiarVentures / PKI.js / examples / CRLComplexExample / es6.js View on Github external
})
	}));
	crlSimpl.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({
			value: "Test"
		})
	}));
	
	crlSimpl.thisUpdate = new Time({
		type: 0,
		value: new Date()
	});
	
	const revokedCertificate = new RevokedCertificate({
		userCertificate: new asn1js.Integer({
			value: 999
		}),
		revocationDate: new Time({
			value: new Date()
		}),
		crlEntryExtensions: new Extensions({
			extensions: [new Extension({
				extnID: "2.5.29.21", // cRLReason
				extnValue: (new asn1js.Enumerated({
					value: 1
				})).toBER(false)
			})]
		})
	});
	
	crlSimpl.revokedCertificates = [];
github PeculiarVentures / PKI.js / src / ResponseData.js View on Github external
* @property {string} [producedAt]
		 * @property {string} [response]
		 * @property {string} [extensions]
		 */
		const names = getParametersValue(parameters, "names", {});

		return (new asn1js.Sequence({
			name: (names.blockName || "ResponseData"),
			value: [
				new asn1js.Constructed({
					optional: true,
					idBlock: {
						tagClass: 3, // CONTEXT-SPECIFIC
						tagNumber: 0 // [0]
					},
					value: [new asn1js.Integer({ name: (names.version || "ResponseData.version") })]
				}),
				new asn1js.Choice({
					value: [
						new asn1js.Constructed({
							name: (names.responderID || "ResponseData.responderID"),
							idBlock: {
								tagClass: 3, // CONTEXT-SPECIFIC
								tagNumber: 1 // [1]
							},
							value: [RelativeDistinguishedNames.schema(names.ResponseDataByName || {
								names: {
									blockName: "ResponseData.byName"
								}
							})]
						}),
						new asn1js.Constructed({
github PeculiarVentures / PKI.js / src / RSAPrivateKey.js View on Github external
* @property {string} [exponent2]
		 * @property {string} [coefficient]
		 * @property {string} [otherPrimeInfosName]
		 * @property {Object} [otherPrimeInfo]
		 */
		const names = getParametersValue(parameters, "names", {});

		return (new asn1js.Sequence({
			name: (names.blockName || ""),
			value: [
				new asn1js.Integer({ name: (names.version || "") }),
				new asn1js.Integer({ name: (names.modulus || "") }),
				new asn1js.Integer({ name: (names.publicExponent || "") }),
				new asn1js.Integer({ name: (names.privateExponent || "") }),
				new asn1js.Integer({ name: (names.prime1 || "") }),
				new asn1js.Integer({ name: (names.prime2 || "") }),
				new asn1js.Integer({ name: (names.exponent1 || "") }),
				new asn1js.Integer({ name: (names.exponent2 || "") }),
				new asn1js.Integer({ name: (names.coefficient || "") }),
				new asn1js.Sequence({
					optional: true,
					value: [
						new asn1js.Repeated({
							name: (names.otherPrimeInfosName || ""),
							value: OtherPrimeInfo.schema(names.otherPrimeInfo || {})
						})
					]
				})
			]
		}));
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / SignedData.js View on Github external
toSchema(encodeFlag = false)
	{
		//region Create array for output sequence
		const outputArray = [];
		
		outputArray.push(new asn1js.Integer({ value: this.version }));
		
		//region Create array of digest algorithms
		outputArray.push(new asn1js.Set({
			value: Array.from(this.digestAlgorithms, algorithm => algorithm.toSchema(encodeFlag))
		}));
		//endregion
		
		outputArray.push(this.encapContentInfo.toSchema());
		
		if("certificates" in this)
		{
			const certificateSet = new CertificateSet({ certificates: this.certificates });
			const certificateSetSchema = certificateSet.toSchema();
			
			outputArray.push(new asn1js.Constructed({
				idBlock: {
github PeculiarVentures / PKI.js / src / OtherPrimeInfo.js View on Github external
fromJSON(json)
	{
		if("r" in json)
			this.prime = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.r, true)) });
		else
			throw new Error("Absent mandatory parameter \"r\"");

		if("d" in json)
			this.exponent = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.d, true)) });
		else
			throw new Error("Absent mandatory parameter \"d\"");

		if("t" in json)
			this.coefficient = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.t, true)) });
		else
			throw new Error("Absent mandatory parameter \"t\"");
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / KeyTransRecipientInfo.js View on Github external
static schema(parameters = {})
	{
		/**
		 * @type {Object}
		 * @property {string} [blockName]
		 * @property {string} [version]
		 * @property {string} [rid]
		 * @property {string} [keyEncryptionAlgorithm]
		 * @property {string} [encryptedKey]
		 */
		const names = getParametersValue(parameters, "names", {});

		return (new asn1js.Sequence({
			name: (names.blockName || ""),
			value: [
				new asn1js.Integer({ name: (names.version || "") }),
				RecipientIdentifier.schema(names.rid || {}),
				AlgorithmIdentifier.schema(names.keyEncryptionAlgorithm || {}),
				new asn1js.OctetString({ name: (names.encryptedKey || "") })
			]
		}));
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / RSAPrivateKey.js View on Github external
this.prime1 = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.p, true, true)) });
		else
			throw new Error("Absent mandatory parameter \"p\"");

		if("q" in json)
			this.prime2 = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.q, true, true)) });
		else
			throw new Error("Absent mandatory parameter \"q\"");

		if("dp" in json)
			this.exponent1 = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.dp, true, true)) });
		else
			throw new Error("Absent mandatory parameter \"dp\"");

		if("dq" in json)
			this.exponent2 = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.dq, true, true)) });
		else
			throw new Error("Absent mandatory parameter \"dq\"");

		if("qi" in json)
			this.coefficient = new asn1js.Integer({ valueHex: stringToArrayBuffer(fromBase64(json.qi, true, true)) });
		else
			throw new Error("Absent mandatory parameter \"qi\"");

		if("oth" in json)
			this.otherPrimeInfos = Array.from(json.oth, element => new OtherPrimeInfo({ json: element }));
	}
	//**********************************************************************************

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 2 years ago

Package Health Score

73 / 100
Full package analysis