Comments (2)
Maybe the problem is with your converters.
Here is my example. It uses PEM converter from @peculiar/x509
and script works without any errors
import { Crypto } from "@peculiar/webcrypto";
import { PemConverter } from "@peculiar/x509";
async function main() {
// GENERATE AND EXPORT KEYS
const WebCrypto = new Crypto();
const { publicKey, privateKey } = await WebCrypto.subtle.generateKey(
{
name: "RSA-PSS",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256"
},
true,
["sign", "verify"]
);
const publicExport = await WebCrypto.subtle.exportKey("spki", publicKey);
const privateExport = await WebCrypto.subtle.exportKey("pkcs8", privateKey);
const publicKeyPem = PemConverter.encode(publicExport, "PUBLIC KEY");
console.log(publicKeyPem);
const privateKeyPem = PemConverter.encode(privateExport, "PRIVATE KEY");
console.log(privateKeyPem);
// IMPORT KEYS
const publicKeyImport = await WebCrypto.subtle.importKey(
"spki",
PemConverter.decode(publicKeyPem)[0],
{ name: "RSA-PSS", hash: "SHA-256" },
true,
["verify"]
);
console.log(publicKeyImport);
const privateKeyImport = await WebCrypto.subtle.importKey(
"pkcs8",
PemConverter.decode(privateKeyPem)[0],
{ name: "RSA-PSS", hash: "SHA-256" },
true,
["sign"]
);
console.log(privateKeyImport);
}
main().catch((e) => console.error(e));
https://codesandbox.io/s/webcrypto-reexport-keys-w7ir18
from webcrypto.
Perfect, this works! Thank you for super quick response :)
from webcrypto.
Related Issues (20)
- "Error: Unknown message digest" caused by crypto.subtle.verify({'name':'ECDSA', 'hash':'SHA-256'}, ...) when bundling via browserify HOT 2
- node14.5安装失败 HOT 1
- Browser support HOT 1
- ArrayBufferViews aren't always aligned with their ArrayBuffer HOT 2
- `oct` JWK should not require alg during importKey HOT 3
- Improve JWK importing
- [webview-crypto] error in `parse` of message & ReferenceError: Property 'abvs' doesn't exist HOT 1
- Can't use AES-WRAP in Electron apps HOT 12
- No support for modulusLength 3072 bit HOT 3
- ECDSA signature variations HOT 3
- Fails to build with the latest typescript HOT 3
- Error: Cannot get schema for 'PrivateKeyInfo' target HOT 3
- Honour hash algo and set salt length when generating RSA-PSS key pairs
- AES encrypt / decrypt with a passphrase HOT 8
- Incompatibility with Node's Webcrypto when using Ed25519 keys HOT 6
- RSA Public Key re-export results in malformed buffer HOT 2
- Implement Ed mechanisms W3
- Merge dependabot Pull-Request to bump json5 from 1.0.1 to 1.0.2
- Crypto.randomUUID() definition breaks on TypeScript 5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webcrypto.