Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sureshreddygovindu opened this issue Apr 28, 2020 · 1 comment
Open

Comments

@sureshreddygovindu
Copy link

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)```
@sureshreddygovindu
Copy link
Author

sureshreddygovindu commented Apr 28, 2020

EC 256Primev1 Private key

-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIHlY0FBpEKL+EVEdkDk9x0OxTEO8HJrPxH2ALoB5+xDIoAoGCCqGSM49
AwEHoUQDQgAE6dDBAXOEbl0bq+kR3JAex4SKz8gVcMCopLdxaeYFdAPOMTdifQuB
1+lSQ6Lyl3Vq8zFrKwW6hU9RQ5gS1tjb6w==
-----END EC PRIVATE KEY-----

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant