You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It also seems like the same error happening when using current version chrome without the flag - #enable-experimental-web-platform-features
node also has a fix but behind the flag --experimental-modules
Steps to Reproduce
Create a file "main.ts" with the contents
import{crypto}from"@std/crypto/crypto";asyncfunctionderiveSharedSecret(privateKey: any,publicKey: any){returnawaitcrypto.subtle.deriveBits({name: "X25519",public: publicKey,},privateKey,128,);}asyncfunctiongenKeys(){constalicesKeyPair=awaitcrypto.subtle.generateKey({name: "X25519",},false,["deriveBits"],)constbobsKeyPair=awaitcrypto.subtle.generateKey({name: "X25519",},false,["deriveBits"],)console.log("Keys changed");return{alicesKeyPair, bobsKeyPair}}asyncfunctionrunExample(){// Generate 2 X25519 key pairs: one for Alice and one for Bob// In more normal usage, they would generate their key pairs// separately and exchange public keys securely// Alice then generates a secret using her private key and Bob's public key.// Bob could generate the same secret using his private key and Alice's public key.const{alicesKeyPair, bobsKeyPair}=awaitgenKeys()constsharedSecretAlice=awaitderiveSharedSecret(//@ts-ignorealicesKeyPair.privateKey,//@ts-ignorebobsKeyPair.publicKey,);letbuffer=newUint8Array(sharedSecretAlice,0,10);console.log(`${buffer}…[${sharedSecretAlice.byteLength} bytes total] (Alice secret)`);constsharedSecretBob=awaitderiveSharedSecret(//@ts-ignorebobsKeyPair.privateKey,//@ts-ignorealicesKeyPair.publicKey,);buffer=newUint8Array(sharedSecretBob,0,10);console.log(`${buffer}…[${sharedSecretAlice.byteLength} bytes total] (Bob secret)`);}if(import.meta.main){runExample()}
Execute the command deno run main.ts
See error
-->
error: Uncaught (in promise) OperationError: Invalid key
return await crypto.subtle.deriveBits(
^
at deriveBits (ext:deno_crypto/00_crypto.js:4514:15)
at SubtleCrypto.deriveBits (ext:deno_crypto/00_crypto.js:1151:26)
at deriveSharedSecret (redacted)
at Object.redacted (redacted)
at async redacted
Describe the bug
crypto.subtle.deriveBits crashes and complains about invalid keys eventho they are correct
Copied the example from mdn
It also seems like the same error happening when using current version chrome without the flag - #enable-experimental-web-platform-features
node also has a fix but behind the flag --experimental-modules
Steps to Reproduce
deno run main.ts
-->
Expected behavior
Environment
The text was updated successfully, but these errors were encountered: