Code Monkey home page Code Monkey logo

Comments (10)

Thalhammer avatar Thalhammer commented on July 21, 2024

Yeah sure:

std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBA....
-----END PRIVATE KEY-----)";

std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
MIIBIjA.....
-----END PUBLIC KEY-----)";

auto token = jwt::create()
		.set_payload_claim("authority", jwt::claim(std::string("your authority")))
		.set_payload_claim("redirecturl", jwt::claim(std::string("https://google.de")))
		.set_payload_claim("sessionid", jwt::claim(std::string("testid")))
		.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));

from jwt-cpp.

pranay-thales avatar pranay-thales commented on July 21, 2024

Thanks for replying. I am new in c++. I wanted to use this token as an encrypted format in string.
although i am able to create the token but how to use it in a string format

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

JWTs are not encrypted (by default) they are only signed. That said the variable "token" in the above example is of type std::string.

from jwt-cpp.

pranay-thales avatar pranay-thales commented on July 21, 2024

Hi While creating the jwt with public and private key i am getting Unhandled exception at in constructor of rsa at line 215 in JWT.h
"std::unique_ptr<BIO, decltype(&BIO_free_all)> privkey_bio(BIO_new(BIO_s_mem()), BIO_free_all);"

The public and private key are unencrypted as well

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

Which exception do you get?

from jwt-cpp.

pranay-thales avatar pranay-thales commented on July 21, 2024

Unhandled exception at 0x00007FFF4D1B8E6C in w3wp.exe: Microsoft C++ exception: jwt::rsa_exception at memory location 0x00000074EB7D9338.

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

This is not the line the error occurs. Catch the exception and post its message.

from jwt-cpp.

pranay-thales avatar pranay-thales commented on July 21, 2024

The error message which i am getting is :
failed to load public key: PEM_read_bio_PUBKEY failed
The public key i am providing is :
string publicKey = "-----BEGIN PUBLIC KEY--------------END PUBLIC KEY----- "
string privateKey = "-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----\r\n"
std::string jwtToken = jwt::create()
.set_payload_claim() //some payload claims set required for oidc
.set_type("JWT")
.sign(jwt::algorithm::rs256(publicKey, privateKey, "", ""));

IS there a provision if i can sign the JWT by providing the private Key only. I am able to achive through hs256 alogo but not in rs256.

from jwt-cpp.

pranay-thales avatar pranay-thales commented on July 21, 2024

We are using RSACryptoServiceProvider in C# which only takes private key and public key is not required for signing. Does that does not apply here in case of rs256 ?

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

Those keys are not valid keys.
Currently the constructor of rsa requires a public key to be present.
However, it should be possible to extract the public key from the private key you have. There should be functions present in your crypto provider to do that. Also I might add a helper to the library to import only a private key.

from jwt-cpp.

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.