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

enable import/export raw ec-keys #21

Closed
armfazh opened this issue Nov 23, 2020 · 3 comments
Closed

enable import/export raw ec-keys #21

armfazh opened this issue Nov 23, 2020 · 3 comments

Comments

@armfazh
Copy link

armfazh commented Nov 23, 2020

currently importKey and exportKey methods work only on public keys, but not on privateKeys.

@microshine
Copy link
Collaborator

Chrome doesn't support raw format for EC private key.
image

Script

var keys = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
var raw = await crypto.subtle.exportKey("raw", keys.privateKey); // Error

var raw = await crypto.subtle.exportKey("raw", keys.publicKey);
console.log(raw);

@peculiar/webcrypto throws AsnSchemaValidationError. Maybe it should be better to use a custom error for that.

AsnSchemaValidationError: Data does not match to PublicKeyInfo ASN1 schema. 
    at Function.fromASN (/Users/microshine/github/pv/webcrypto/node_modules/@peculiar/asn1-schema/build/cjs/parser.js:56:23)
    at Function.parse (/Users/microshine/github/pv/webcrypto/node_modules/@peculiar/asn1-schema/build/cjs/parser.js:29:26)
    at Function.exportKey (/Users/microshine/github/pv/webcrypto/build/webcrypto.js:1449:60)
    at EcdsaProvider.onExportKey (/Users/microshine/github/pv/webcrypto/build/webcrypto.js:1578:25)
    at EcdsaProvider.exportKey (/Users/microshine/github/pv/webcrypto/node_modules/webcrypto-core/build/webcrypto-core.js:203:33)
    at SubtleCrypto.exportKey (/Users/microshine/github/pv/webcrypto/node_modules/webcrypto-core/build/webcrypto-core.js:838:39)
    at main (/Users/microshine/github/pv/webcrypto/test.ts:7:35) {
  schemas: [ 'PublicKeyInfo' ]
}

@armfazh Do you have any ideas how EC private key raw must look like?

@armfazh
Copy link
Author

armfazh commented Nov 26, 2020

Do you have any ideas how EC private key raw must look like?

For P-256, it's an arraybuffer of 32 bytes.

@armfazh
Copy link
Author

armfazh commented Nov 26, 2020

after RTFM specification: https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations
Private keys cannot be exported in raw format, but they can be exported as jwk or pkcs8.
closing.

@armfazh armfazh closed this as completed Nov 26, 2020
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

2 participants