Skip to content

PKCS#8 private key ASN1 object for ECC Private key pem #1

@sureshreddygovindu

Description

@sureshreddygovindu

Hi, I'm working on p12 generation for ECC keytype pem and certs.

I'm getting error when I'm passing EC private key to below logic, can you guide me if you have any idea?

const { PEM, ASN1, Class, Tag } = require('@fidm/asn1')
 
// ASN.1 Template https://tools.ietf.org/html/rfc5208
const privateKeyValidator = {
    name: 'PrivateKeyInfo',
    class: Class.UNIVERSAL,
    tag: Tag.SEQUENCE,
    capture: 'privateKeyInfo',
    value: [{
      name: 'PrivateKeyInfo.Version',
      class: Class.UNIVERSAL,
      tag: Tag.INTEGER,
      capture: 'privateKeyVersion'
    }, {
      name: 'PrivateKeyInfo.AlgorithmIdentifier',
      class: Class.UNIVERSAL,
      tag: Tag.SEQUENCE,
      value: [{
        name: 'PrivateKeyAlgorithmIdentifier.algorithm',
        class: Class.UNIVERSAL,
        tag: Tag.OID,
        capture: 'privateKeyOID'
      }]
    }, {
      name: 'PrivateKeyInfo.PrivateKey',
      class: Class.UNIVERSAL,
      tag: Tag.OCTETSTRING,
      capture: 'privateKey'
    }]
  }
 
const rootkey = PEM.parse(fs.readFileSync('ecctestPK.pem'))[0];
console.log(rootkey)
const captures = ASN1.parseDERWithTemplate(rootkey.body, privateKeyValidator);

console.log("******************")
console.log(captures)```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions