How to use the pkijs.getCrypto function in pkijs

To help you get started, we’ve selected a few pkijs 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 / CAdES.js / src / ArchiveTimeStampV3.js View on Github external
getStampingBuffer(cmsSignedData, signerIndex, parameters)
	{
		//region Initial variables
		let sequence = Promise.resolve();
		
		let hashAlgorithm = "SHA-256";
		
		let content = new ArrayBuffer(0);
		let aTSHashIndex = new ArrayBuffer(0);
		
		let resultBuffer = new ArrayBuffer(0);
		//endregion
		
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			return Promise.reject("Unable to create WebCrypto object");
		//endregion
		
		//region Check input parameters
		if("hashAlgorithm" in parameters)
			hashAlgorithm = parameters.hashAlgorithm;
		
		if("content" in parameters)
			content = parameters.content; // ArrayBuffer
		else
		{
			if("eContent" in cmsSignedData.encapContentInfo)
			{
				if((cmsSignedData.encapContentInfo.eContent.idBlock.tagClass === 1) &&
					(cmsSignedData.encapContentInfo.eContent.idBlock.tagNumber === 4))
github PeculiarVentures / CAdES.js / src / OcspResponsesID.js View on Github external
let ocspResponse;
		//endregion
		
		//region Check input parameters
		if("hashAlgorithm" in parameters)
			hashAlgorithm = parameters.hashAlgorithm;
		
		if("ocspResponse" in parameters)
			ocspResponse = parameters.ocspResponse; // in_window.org.pkijs.simpl.OCSP_RESPONSE
		else
			return Promise.reject("Parameter \"ocspResponse\" is mandatory for making \"OcspResponsesID\"");
		//endregion
		
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			return Promise.reject("Unable to create WebCrypto object");
		//endregion
		
		//region Fill correct value for "hashIndAlgorithm"
		sequence = sequence.then(
			() => {
				if(hashAlgorithm.toUpperCase() !== "SHA-1")
				{
					const oid = getOIDByAlgorithm({ name: hashAlgorithm });
					if(oid === "")
						return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
					
					this.ocspRepHash = new OtherHashAlgAndValue({
						hashAlgorithm: new AlgorithmIdentifier({
							algorithmId: oid,
github PeculiarVentures / CAdES.js / src / CAdESCTimestamp.js View on Github external
getStampingBuffer(cmsSignedData, signerIndex, parameters = {})
	{
		//region Initial variables
		let sequence = Promise.resolve();
		
		let hashAlgorithm = "SHA-256";
		
		let resultBuffer = new ArrayBuffer(0);
		
		let signatureTimeStamp; // SignatureTimeStamp
		let completeCertificateReferences; // CompleteCertificateReferences
		let completeRevocationReferences; // CompleteRevocationReferences
		//endregion
		
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			return Promise.reject("Unable to create WebCrypto object");
		//endregion
		
		//region Check input parameters
		if("hashAlgorithm" in parameters)
			hashAlgorithm = parameters.hashAlgorithm;
		
		if("signatureTimeStamp" in parameters)
			signatureTimeStamp = parameters.signatureTimeStamp;
		else
			return Promise.reject("Parameter \"signatureTimeStamp\" is mandatory for making \"CAdES-C-Timestamp\" attribute");
		
		if("completeCertificateReferences" in parameters)
			completeCertificateReferences = parameters.completeCertificateReferences;
		else
github PeculiarVentures / CAdES.js / src / ATSHashIndex.js View on Github external
{
		//region Initial variables
		const _this = this;
		
		let sequence = Promise.resolve();
		
		let hashAlgorithm = "SHA-256";
		//endregion
		
		//region Check input parameters
		if("hashAlgorithm" in parameters)
			hashAlgorithm = parameters.hashAlgorithm;
		//endregion
		
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			return Promise.reject("Unable to create WebCrypto object");
		//endregion
		
		//region Fill correct value for "hashIndAlgorithm"
		sequence = sequence.then(
			() => {
				if(hashAlgorithm.toUpperCase() !== "SHA-256")
				{
					const oid = getOIDByAlgorithm({ name: hashAlgorithm });
					if(oid === "")
						return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
					
					_this.hashIndAlgorithm = new AlgorithmIdentifier({
						algorithmId: oid,
						algorithmParams: new asn1js.Null()
github YuryStrozhevsky / CTjs / src / MerkleTreeLeaf.js View on Github external
async hash(hashName = "SHA-256")
	{
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			throw new Error("Unable to create WebCrypto object");
		//endregion
		
		const prefixedBuffer = utilConcatBuf((new Uint8Array([0x00])).buffer, this.buffer);
		
		return await crypto.digest({ name: hashName }, prefixedBuffer);
	}
	//**********************************************************************************
github YuryStrozhevsky / CTjs / src / TransItem.js View on Github external
async hash(hashName = "SHA-256")
	{
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			throw new Error("Unable to create WebCrypto object");
		//endregion
		
		const prefixedBuffer = utilConcatBuf((new Uint8Array([0x00])).buffer, this.buffer);
		
		return await crypto.digest({ name: hashName }, prefixedBuffer);
	}
	//**********************************************************************************
github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
//region Initial variables
	let sequence = Promise.resolve();
	
	const responses = [];
	
	let basicResponse;
	let ocspResponse;
	
	let ocspPublicKey;
	
	let asn1CertSimpl = asn1js.fromBER(stringToArrayBuffer(atob(OCSPcert)));
	const certSimpl = new Certificate({ schema: asn1CertSimpl.result });
	//endregion
	
	//region Get a "crypto" extension
	const crypto = getCrypto();
	if(typeof crypto === "undefined")
		return Promise.reject("No WebCrypto extension found");
	//endregion
	
	sequence = sequence.then(() => 
	{
		//region Get making OCSP response for each certificate in the request 
		for(let i = 0; i < request.tbsRequest.requestList.length; i++)
		{
			//region Initial variables 
			let valid = false;
			//endregion 
			
			//region Check the certificate for "to be valid" 
			for(let j = 0; j < validCertificates.length; j++)
			{
github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
let tstInfo;
	
	const signerInfo = new SignerInfo({
		version: 1,
		sid: new IssuerAndSerialNumber({
			issuer: certSimpl.issuer,
			serialNumber: certSimpl.serialNumber
		})
	});
	signerInfo.signedAttrs = new SignedAndUnsignedAttributes({
		type: 0
	});
	//endregion
	
	//region Get a "crypto" extension
	const crypto = getCrypto();
	if(typeof crypto === "undefined")
		return Promise.reject("No WebCrypto extension found");
	//endregion
	
	sequence = sequence.then(() => certSimpl.getPublicKey());
	
	sequence = sequence.then(result =>
	{
		tspPublicKey = result;
		
		const parameters = getAlgorithmParameters(result.algorithm.name, "importKey");
		
		return crypto.importKey("pkcs8",
			stringToArrayBuffer(atob(TSPkey)),
			parameters.algorithm,
			true,
github YuryStrozhevsky / CTjs / src / PreCert.js View on Github external
static async fromCertificateAndIssuer(parameters)
	{
		//region Initial variables
		const result = new PreCert();
		//endregion
		
		//region Get a "crypto" extension
		const crypto = getCrypto();
		if(typeof crypto === "undefined")
			return Promise.reject("Unable to create WebCrypto object");
		//endregion
		
		//region Check input parameters
		if(("certificate" in parameters) === false)
			throw new Error("Missing mandatory parameter: certificate");
		
		if(("issuer" in parameters) === false)
			throw new Error("Missing mandatory parameter: issuer");
		//endregion
		
		//region Remove certificate extension
		for(let i = 0; i < parameters.certificate.extensions.length; i++)
		{
			switch(parameters.certificate.extensions[i].extnID)
github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
let cmsSignedSimpl;
	
	const ocspRequest = new OCSPRequest();
	
	const aTSHashIndex = new ATSHashIndex();
	
	let asn1 = asn1js.fromBER(stringToArrayBuffer(atob(User10cert)));
	const certSimpl = new Certificate({ schema: asn1.result });
	
	asn1 = asn1js.fromBER(stringToArrayBuffer(atob(CAcert)));
	const caCertSimpl = new Certificate({ schema: asn1.result });
	//endregion
	
	//region Get a "crypto" extension
	const crypto = getCrypto();
	if(typeof crypto === "undefined")
		return Promise.reject("No WebCrypto extension found");
	//endregion

	sequence = sequence.then(() => certSimpl.getPublicKey());
	
	sequence = sequence.then(result =>
	{
		userPublicKey = result;
		
		return crypto.importKey("pkcs8",
			stringToArrayBuffer(atob(User10key)),
			{
				name: result.algorithm.name,
				hash: result.algorithm.hash || {}
			},

pkijs

Public Key Infrastructure (PKI) is the basis of how identity and key management is performed on the web today. PKIjs is a pure JavaScript library implementing the formats that are used in PKI applications. It is built on WebCrypto and aspires to make it p

BSD-3-Clause
Latest version published 5 days ago

Package Health Score

81 / 100
Full package analysis