Created
August 15, 2019 06:20
-
-
Save ronanyeah/4ec99ba3cf5d8c1f5db2cbb9edf19ff2 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 { publicKey, privateKey } = await crypto.generateKey( | |
| { | |
| name: "RSA-OAEP", | |
| modulusLength: 2048, | |
| publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
| hash: "SHA-256" | |
| }, | |
| true, | |
| ["encrypt", "decrypt"] | |
| ); | |
| const encryptedText = await crypto | |
| .encrypt( | |
| { name: "RSA-OAEP" }, | |
| publicKey, | |
| stringToArrayBuffer(encodeURI("plaintext")) | |
| ) | |
| .then(arrayBufferToString); | |
| const res = await crypto | |
| .decrypt( | |
| { name: "RSA-OAEP" }, | |
| privateKey, | |
| stringToArrayBuffer(encryptedText) | |
| ) | |
| .then(arrayBufferToString) | |
| .then(decodeURI); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment