How to use the asn1js.BitString 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 / P7BSimpleExample / es6.js View on Github external
type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));
	
	certSimpl.notBefore.value = new Date(2013, 0, 1);
	certSimpl.notAfter.value = new Date(2016, 0, 1);
	
	certSimpl.extensions = []; // Extensions are not a part of certificate by default, it's an optional array
	
	//region "KeyUsage" extension
	const bitArray = new ArrayBuffer(1);
	const bitView = new Uint8Array(bitArray);
	bitView[0] |= 0x02; // Key usage "cRLSign" flag
	//bitView[0] = bitView[0] | 0x04; // Key usage "keyCertSign" flag
	
	const keyUsage = new asn1js.BitString({ valueHex: bitArray });
	certSimpl.extensions.push(new Extension({
		extnID: "2.5.29.15",
		critical: false,
		extnValue: keyUsage.toBER(false),
		parsedValue: keyUsage // Parsed value for well-known extensions
	}));
	//endregion
	//endregion
	
	//region Create a new key pair
	sequence = sequence.then(() =>
	{
		//region Get default algorithm parameters for key generation
		const algorithm = getAlgorithmParameters(signAlg, "generatekey");
		if("hash" in algorithm.algorithm)
			algorithm.algorithm.hash.name = hashAlg;
github PeculiarVentures / PKI.js / src / DistributionPoint.js View on Github external
{
			if(asn1.result.distributionPoint.idBlock.tagNumber === 0) // GENERAL_NAMES variant
				this.distributionPoint = Array.from(asn1.result.distributionPointNames, element => new GeneralName({ schema: element }));

			if(asn1.result.distributionPoint.idBlock.tagNumber === 1) // RDN variant
			{
				this.distributionPoint = new RelativeDistinguishedNames({
					schema: new asn1js.Sequence({
						value: asn1.result.distributionPoint.valueBlock.value
					})
				});
			}
		}

		if("reasons" in asn1.result)
			this.reasons = new asn1js.BitString({ valueHex: asn1.result.reasons.valueBlock.valueHex });

		if("cRLIssuer" in asn1.result)
			this.cRLIssuer = Array.from(asn1.result.cRLIssuerNames, element => new GeneralName({ schema: element }));
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / CertificationRequest.js View on Github external
sequence = sequence.then(result =>
		{
			this.signatureValue = new asn1js.BitString({ valueHex: result });
		});
		//endregion
github PeculiarVentures / PKI.js / src / CertificationRequest.js View on Github external
* @property {string} [signatureAlgorithm]
		 * @property {string} [signatureValue]
		 */
		const names = getParametersValue(parameters, "names", {});
		
		return (new asn1js.Sequence({
			value: [
				CertificationRequestInfo(names.certificationRequestInfo || {}),
				new asn1js.Sequence({
					name: (names.signatureAlgorithm || "signatureAlgorithm"),
					value: [
						new asn1js.ObjectIdentifier(),
						new asn1js.Any({ optional: true })
					]
				}),
				new asn1js.BitString({ name: (names.signatureValue || "signatureValue") })
			]
		}));
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / examples / PKCS12SimpleExample / es6.js View on Github external
const keyLocalIDView = new Uint8Array(keyLocalIDBuffer);
	
	getRandomValues(keyLocalIDView);
	
	const certLocalIDBuffer = new ArrayBuffer(4);
	const certLocalIDView = new Uint8Array(certLocalIDBuffer);
	
	getRandomValues(certLocalIDView);
	
	//region "KeyUsage" attribute
	const bitArray = new ArrayBuffer(1);
	const bitView = new Uint8Array(bitArray);
	
	bitView[0] |= 0x80;
	
	const keyUsage = new asn1js.BitString({
		valueHex: bitArray,
		unusedBits: 7
	});
	//endregion
	
	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 });
	
	//region Add "keyUsage" attribute
github PeculiarVentures / PKI.js / src / PublicKeyInfo.js View on Github external
algorithmParams: new asn1js.ObjectIdentifier({ value: this.parsedKey.namedCurve })
					});
					break;
				case "RSA":
					this.parsedKey = new RSAPublicKey({ json });
					
					this.algorithm = new AlgorithmIdentifier({
						algorithmId: "1.2.840.113549.1.1.1",
						algorithmParams: new asn1js.Null()
					});
					break;
				default:
					throw new Error(`Invalid value for "kty" parameter: ${json.kty}`);
			}
			
			this.subjectPublicKey = new asn1js.BitString({ valueHex: this.parsedKey.toSchema().toBER(false) });
		}
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / BasicOCSPResponse.js View on Github external
sequence = sequence.then(result =>
		{
			this.signature = new asn1js.BitString({ valueHex: result });
		});
		//endregion
github PeculiarVentures / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
}

    ["x", "y"].forEach((name) => {
        if (name in jwk) {
            parsedKey[name] = getCoordinate((jwk as any)[name], coordinateLength);
        } else {
            throw new Error(`Absent mandatory parameter '${name}'`);
        }
    });

    const spki = new PublicKeyInfo();
    spki.algorithm = new AlgorithmIdentifier({
        algorithmId: "1.2.840.10045.2.1",
        algorithmParams: new Asn1Js.ObjectIdentifier({ value: parsedKey.namedCurve }),
    });
    spki.subjectPublicKey = new Asn1Js.BitString({ valueHex: parsedKey.toSchema().toBER(false) });

    return spki.toSchema().toBER(false);
}
github PeculiarVentures / PKI.js / src / Signature.js View on Github external
static defaultValues(memberName)
	{
		switch(memberName)
		{
			case "signatureAlgorithm":
				return new AlgorithmIdentifier();
			case "signature":
				return new asn1js.BitString();
			case "certs":
				return [];
			default:
				throw new Error(`Invalid member name for Signature class: ${memberName}`);
		}
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / PublicKeyInfo.js View on Github external
static defaultValues(memberName)
	{
		switch(memberName)
		{
			case "algorithm":
				return new AlgorithmIdentifier();
			case "subjectPublicKey":
				return new asn1js.BitString();
			default:
				throw new Error(`Invalid member name for PublicKeyInfo class: ${memberName}`);
		}
	}
	//**********************************************************************************

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