Comments (10)
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.
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.
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.
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.
Which exception do you get?
from jwt-cpp.
Unhandled exception at 0x00007FFF4D1B8E6C in w3wp.exe: Microsoft C++ exception: jwt::rsa_exception at memory location 0x00000074EB7D9338.
from jwt-cpp.
This is not the line the error occurs. Catch the exception and post its message.
from jwt-cpp.
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.
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.
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)
- Create a test for the undefined sanitizer
- HMAC key should be an array of bytes, not a character string HOT 9
- x86/Win32 compilation and using boost json HOT 2
- Private Key Signing vs Signing from Service Account file HOT 5
- undefined reference error in compiling HOT 9
- what secret format should i use for HS512 algorithm HOT 1
- Release status of 0.7.0-rc.0 HOT 3
- Guide to Setting Up jwt-cpp? HOT 4
- Building example: no matching function for call to ‘decode(std::string&)’ HOT 1
- Compilation error: no matching function for call to ‘decode(std::string&)’ HOT 2
- Build Errors For picojson.h? HOT 8
- Getting Error - namespace "jwt" has no member "claims" HOT 6
- Unable to generate token using ed25519 HOT 2
- Use of Builder explicitly
- Need help : How to Implement JWT Operations from Python Using jwt-cpp ? HOT 5
- How to use payload and get the payload data HOT 7
- Boost JSON traits kind of buggy HOT 5
- How to verify a jwt HOT 3
- Invalid input: not within alphabet HOT 6
- Locking in libcrypto in multi threaded app HOT 6
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 jwt-cpp.