How to use the @peculiar/asn1-schema.AsnSerializer.serialize function in @peculiar/asn1-schema

To help you get started, we’ve selected a few @peculiar/asn1-schema 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 / webcrypto / test / asn.ts View on Github external
it("serialize", () => {
        const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPublicKey });

        const keyInfo = new asn.PublicKeyInfo();
        keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
        keyInfo.publicKeyAlgorithm.parameters = null;
        keyInfo.publicKey = AsnSerializer.serialize(key);

        const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo));
        assert.equal(asnKeyInfo.equals(bytes), true);
      });
github PeculiarVentures / webcrypto / test / asn.ts View on Github external
it("serialize", () => {
        const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPrivateKey });

        const keyInfo = new asn.PrivateKeyInfo();
        keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
        keyInfo.privateKeyAlgorithm.parameters = null;
        keyInfo.privateKey = AsnSerializer.serialize(key);

        const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo));
        assert.equal(asnKeyInfo.equals(bytes), true);
      });
github PeculiarVentures / webcrypto-liner / src / mechs / ec / crypto.ts View on Github external
private static exportPkcs8Key(key: EcCryptoKey) {
    const keyInfo = new asn.PrivateKeyInfo();
    keyInfo.privateKeyAlgorithm.algorithm = this.ASN_ALGORITHM;
    keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(
      new asn.ObjectIdentifier(getOidByNamedCurve(key.algorithm.namedCurve)),
    );
    keyInfo.privateKey = AsnSerializer.serialize(this.exportEcKey(key));

    return AsnSerializer.serialize(keyInfo);
  }
github PeculiarVentures / webcrypto / src / mechs / ec / public_key.ts View on Github external
public fromJSON(json: JsonWebKey) {
    const key = JsonParser.fromJSON(json, { targetSchema: asn.EcPublicKey });

    const keyInfo = new asn.PublicKeyInfo();
    keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
    keyInfo.publicKeyAlgorithm.parameters = AsnSerializer.serialize(
      new ObjectIdentifier(getOidByNamedCurve(json.crv!)),
    );
    keyInfo.publicKey = AsnSerializer.toASN(key).valueHex;

    this.data = Buffer.from(AsnSerializer.serialize(keyInfo));

    return this;
  }
}
github PeculiarVentures / webcrypto / src / mechs / ec / crypto.ts View on Github external
protected static async importPrivateKey(asnKey: asn.EcPrivateKey, algorithm: EcKeyImportParams, extractable: boolean, keyUsages: KeyUsage[]) {
    const keyInfo = new asn.PrivateKeyInfo();
    keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
    keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(new ObjectIdentifier(getOidByNamedCurve(algorithm.namedCurve)));
    keyInfo.privateKey = AsnSerializer.serialize(asnKey);

    const key = new EcPrivateKey();
    key.data = Buffer.from(AsnSerializer.serialize(keyInfo));

    key.algorithm = Object.assign({}, algorithm) as EcKeyAlgorithm;
    key.extractable = extractable;
    key.usages = keyUsages;

    return key;
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / crypto.ts View on Github external
protected static importPublicKey(asnKey: asn.RsaPublicKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]) {
    const keyInfo = new asn.PublicKeyInfo();
    keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
    keyInfo.publicKeyAlgorithm.parameters = null;
    keyInfo.publicKey = AsnSerializer.serialize(asnKey);

    const key = new RsaPublicKey();
    key.data = Buffer.from(AsnSerializer.serialize(keyInfo));

    key.algorithm = Object.assign({}, algorithm) as RsaHashedKeyAlgorithm;
    key.algorithm.publicExponent = new Uint8Array(asnKey.publicExponent);
    key.algorithm.modulusLength = asnKey.modulus.byteLength << 3;
    key.extractable = extractable;
    key.usages = keyUsages;

    return key;
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / private_key.ts View on Github external
public fromJSON(json: JsonWebKey) {
    const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPrivateKey });

    const keyInfo = new asn.PrivateKeyInfo();
    keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
    keyInfo.privateKeyAlgorithm.parameters = null;
    keyInfo.privateKey = AsnSerializer.serialize(key);

    this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / public_key.ts View on Github external
public fromJSON(json: JsonWebKey) {
    const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPublicKey });

    const keyInfo = new asn.PublicKeyInfo();
    keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
    keyInfo.publicKeyAlgorithm.parameters = null;
    keyInfo.publicKey = AsnSerializer.serialize(key);

    this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  }
}
github PeculiarVentures / webcrypto-liner / src / mechs / rsa / crypto.ts View on Github external
private static exportPkcs8Key(key: RsaCryptoKey) {
    const keyInfo = new asn.PrivateKeyInfo();
    keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
    keyInfo.privateKeyAlgorithm.parameters = null;
    keyInfo.privateKey = AsnSerializer.serialize(this.exportAsmKey(key.data));

    return AsnSerializer.serialize(keyInfo);
  }

@peculiar/asn1-schema

Decorators for ASN.1 schemas building

MIT
Latest version published 7 months ago

Package Health Score

71 / 100
Full package analysis