Comments (6)
Hi, to generate a CryptoKey
or a CryptoKeyPair
from existing keys you can use the importKey
method from the Web Crypto API. You should be able to use your .pem files with this method.
Please take a look at this documentation and the containing examples and let me know if they helped: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
If you just want to generate a CryptoKeyPair
I added an example for the RS384
algorithm here.
Thanks!
from djwt.
Looks like pkcs8 is not available in deno 🤔
from djwt.
Easiest way is to declare a Global var for your key and use it to create and verify your JWT.
Just put this code in your Starting Application
declare global {
var keys: any;
interface Window {
keys: any;
}
}
window.keys = await crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 4096,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-384",
},
true,
["verify", "sign"],
)
##to create JWT token:
const jwtpayload: Payload = {
sub: "1234567890",
name: "John Doe",
admin: true,
iat: 1516239022,
}
const jwtheader: Header = {
alg: "RS384",typ: "JWT"
}
const jwt = await create(jwtheader,jwtpayload,keys.privateKey)
##to verify:
await verify(jwt,keys.publicKey)
##I think this is not a good practice but it works, hope it will help.
##Edited: Derived from RSA of timonson.
from djwt.
For my application I need to use RSA and I need the tokens to be valid even after a restart.
from djwt.
Hi @itohatweb , pkcs8 has been implemented by the deno authors now.
I added an example for generating, exporting and importing a key in pkcs8 format here. Does it help?
from djwt.
Yes thank you.
from djwt.
Related Issues (20)
- Feature Request: Support JSON Web Key Sets (JWKS) HOT 3
- mod.ts missing on deno.land HOT 4
- Verify Web Token Crypto from a different file (middleware) HOT 1
- There's no permanent key available. HOT 13
- need some real world examples HOT 7
- Cannot find name 'HmacKeyAlgorithm' HOT 3
- Expected comma with deno bundle (GitHub Actions) HOT 3
- Argument of type '"jwk"' is not assignable to parameter of type '"raw" | "pkcs8" | "spki". in Deno v1.18.1 HOT 2
- Verify fail HOT 1
- exp/nbf leeway should be configurable HOT 4
- Node or browser version? HOT 2
- Moving to JavaScript with JSDoc? HOT 2
- Unexpected change of JWT Key HOT 10
- The jwt's signature does not match the verification signature. HOT 4
- Cannot verify token/secret which verifies successfully using Node HOT 3
- Cannot create token Uncaught TypeError: Cannot read properties of undefined (reading 'name') HOT 1
- How to safe the CryptoKey for the djwt HOT 1
- Can you publish djwt to npmjs ? HOT 13
- can create but not validate a JWT with a non-object payload HOT 3
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 djwt.