0

I hope someone can help. I have been using cryptico.js and have been generating keys via:

var RSAkey = cryptico.generateRSAKey(passphrase, 512);
var publicKeyString = cryptico.publicKeyString(RSAkey);

Giving me clean good access to a public key, like: vnY5f+HVUQa2oBZKsb2LUgTlso/wtVsA5Ytqlr1RL13xVN81mnIHoL/5/8CKG4rQ/vQfnBAUBYfJzBQGeAXYnw==

I am switching to use WebCrypto API as I want to use a different key type:

promise_key = crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256", hash: {name: "SHA-256"} }, true, ["sign", "verify"]);
promise_key.then(function(key) {
    private_key_object = key.privateKey;
    public_key_object = key.publicKey;
    console.log(key.publicKey);
});

I am wanting to get the Public Key String as I do with cryptico, and I am sure I am doing something very silly but I can't seem to get it.

I have used crypto.subtle.exportKey with 'spki', 'raw' and 'jwk' options but no joy.

Even if I use RSA to generate keys instead of ECDSA, I still get the same.

What am I doing wrong, please?

Thanks a lot

user1910714
  • 109
  • 8

1 Answers1

0

The CryptoKey itself is not viewable via a simple console.log. It first needs to be transformed into the desired format. You can use exportKey for that (as long as you have set extractable to `true - which you did).

Here are some examples.

Jclangst
  • 1,274
  • 7
  • 11