Created
February 11, 2025 18:22
-
-
Save HamdaanAliQuatil/2170d5336ed18e9261e6b77a434dae63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const x25519_key = await crypto.subtle.generateKey( | |
| { name: "X25519" }, | |
| true, // Extractable | |
| ["deriveKey", "deriveBits"] | |
| ); | |
| // Export the keys | |
| const privateKeyJwk = await crypto.subtle.exportKey("pkcs8", x25519_key.privateKey); | |
| const publicKeyJwk = await crypto.subtle.exportKey("spki", x25519_key.publicKey); | |
| // Convert ArrayBuffer to Base64 for readability | |
| const arrayBufferToBase64 = (buffer) => { | |
| const binary = String.fromCharCode(...new Uint8Array(buffer)); | |
| return btoa(binary); | |
| }; | |
| console.log("Private Key (Base64 PKCS8):", arrayBufferToBase64(privateKeyJwk)); | |
| console.log("Public Key (Base64 SPKI):", arrayBufferToBase64(publicKeyJwk)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment