Giter Site home page Giter Site logo

How to use Cert files about djwt HOT 6 CLOSED

itohatweb avatar itohatweb commented on August 24, 2024
How to use Cert files

from djwt.

Comments (6)

timonson avatar timonson commented on August 24, 2024

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.

itohatweb avatar itohatweb commented on August 24, 2024

Looks like pkcs8 is not available in deno 🤔

from djwt.

koanzen avatar koanzen commented on August 24, 2024

@ts

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.

itohatweb avatar itohatweb commented on August 24, 2024

For my application I need to use RSA and I need the tokens to be valid even after a restart.

from djwt.

timonson avatar timonson commented on August 24, 2024

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.

itohatweb avatar itohatweb commented on August 24, 2024

Yes thank you.

from djwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.