0

I generate the ECDH keys in this way

let _this = this;
window.crypto.subtle.generateKey(
        {
            name: "ECDH",
            namedCurve: "P-256", // the curve name
        },
        true, // <== Here if you want it to be exportable !!
        ["deriveKey", "deriveBits"] // usage
    )
    .then(key => {
        _this.keys = key;
        // export
        return window.crypto.subtle.exportKey(
            "raw", //can be "jwk" (public or private), "raw" (public only), "spki" (public only), or "pkcs8" (private only)
            _this.keys.publicKey
        )
        .then(rawPublicKey => {
            _this.publicKey = rawPublicKey;
            return rawPublicKey;
        })
    })

In this way i have the cryptokeys and the raw (x,y coords) public key.
I would use the keys for using it for ECDSA

How can I do that?

Vito Lipari
  • 795
  • 8
  • 35

1 Answers1

0
window.crypto.subtle.generateKey({
                name: "ECDSA",
                namedCurve: curve, //can be "P-256", "P-384", or "P-521"
            },
            true, //whether the key is extractable (i.e. can be used in exportKey)
            ["sign", "verify"] //can be any combination of "sign" and "verify"
        )
        .then(function(key) {

        publicKey = key.publicKey;
        privateKey = key.privateKey;
        // For Demo Purpos Only Exported in JWK format
        window.crypto.subtle.exportKey("jwk", key.publicKey).then(
            function(keydata) {
                publicKeyhold = keydata;
                publicKeyJson = JSON.stringify(publicKeyhold);
                document.getElementById("ecdsapublic").value = publicKeyJson;
            }
        );

        window.crypto.subtle.exportKey("jwk", key.privateKey).then(
            function(keydata) {
                privateKeyhold = keydata;
                privateKeyJson = JSON.stringify(privateKeyhold);
                document.getElementById("ecdsaprivate").value = privateKeyJson;

as you can see you can generate ECDSA keys using global method they will be different , you can't use ECDH keys } );

Rahul Rana
  • 455
  • 2
  • 7