Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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?
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.