How to use the pkijs.AlgorithmIdentifier 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 / node-webcrypto-p11 / src / mechs / ec / crypto.ts View on Github external
default:
      }
    } else {
      throw new Error("Absent mandatory parameter \"crv\"");
    }

    ["d"].forEach((name) => {
      if (name in jwk) {
        parsedKey.privateKey = new Asn1Js.OctetString({ valueHex: this.getCoordinate((jwk as any)[name], coordinateLength) });
      } else {
        throw new Error(`Absent mandatory parameter '${name}'`);
      }
    });

    const pkcs8 = new pkijs.PrivateKeyInfo();
    pkcs8.privateKeyAlgorithm = new pkijs.AlgorithmIdentifier({
      algorithmId: "1.2.840.10045.2.1",
      algorithmParams: new Asn1Js.ObjectIdentifier({ value: parsedKey.namedCurve }),
    });
    pkcs8.privateKey = new Asn1Js.OctetString({ valueHex: parsedKey.toSchema().toBER(false) });

    return pkcs8.toSchema().toBER(false);
  }
github PeculiarVentures / CAdES.js / src / ESSCertIDv2.js View on Github external
() => {
				if(hashAlgorithm.toUpperCase() !== "SHA-256")
				{
					const oid = getOIDByAlgorithm({ name: hashAlgorithm });
					if(oid === "")
						return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
					
					_this.hashAlgorithm = new AlgorithmIdentifier({
						algorithmId: oid,
						algorithmParams: new asn1js.Null()
					});
				}
				
				return Promise.resolve();
			}
		);
github PeculiarVentures / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
default:
        }
    } else {
        throw new Error("Absent mandatory parameter \"crv\"");
    }

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

    const pkcs8 = new PrivateKeyInfo();
    pkcs8.privateKeyAlgorithm = new AlgorithmIdentifier({
        algorithmId: "1.2.840.10045.2.1",
        algorithmParams: new Asn1Js.ObjectIdentifier({ value: parsedKey.namedCurve }),
    });
    pkcs8.privateKey = new Asn1Js.OctetString({ valueHex: parsedKey.toSchema().toBER(false) });

    return pkcs8.toSchema().toBER(false);
}
github PeculiarVentures / node-webcrypto-p11 / src / mechs / ec / crypto.ts View on Github external
default:
      }
    } else {
      throw new Error("Absent mandatory parameter \"crv\"");
    }

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

    const spki = new pkijs.PublicKeyInfo();
    spki.algorithm = new pkijs.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 / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
default:
        }
    } else {
        throw new Error("Absent mandatory parameter \"crv\"");
    }

    ["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 / CAdES.js / src / ESSCertIDv2.js View on Github external
issuerSerial: {
						names: {
							blockName: "issuerSerial"
						}
					}
				}
			})
		);
		
		if(asn1.verified === false)
			throw new Error("Object's schema was not verified against input data for ESSCertIDv2");
		//endregion
		
		//region Get internal properties from parsed schema
		if("hashAlgorithm" in asn1.result)
			this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
		
		this.certHash = asn1.result.serialNumber;
		this.issuerSerial = new IssuerSerial({ schema: asn1.result.issuerSerial });
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / CAdES.js / src / OtherHashAlgAndValue.js View on Github external
hashAlgorithm: {
						names: {
							blockName: "hashAlgorithm"
						}
					},
					hashValue: "hashValue"
				}
			})
		);
		
		if(asn1.verified === false)
			throw new Error("Object's schema was not verified against input data for OtherHashAlgAndValue");
		//endregion
		
		//region Get internal properties from parsed schema
		this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
		this.hashValue = asn1.result.hashValue;
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / CAdES.js / src / OtherCertID.js View on Github external
() => {
				if(hashAlgorithm.toUpperCase() !== "SHA-1")
				{
					const oid = getOIDByAlgorithm({ name: hashAlgorithm });
					if(oid === "")
						return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
					
					_this.otherCertHash = new OtherHashAlgAndValue({
						hashAlgorithm: new AlgorithmIdentifier({
							algorithmId: oid,
							algorithmParams: new asn1js.Null()
						})
					});
				}
				else
					_this.otherCertHash = new asn1js.OctetString();
				
				return Promise.resolve();
			}
		);

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 4 months ago

Package Health Score

80 / 100
Full package analysis