Comments (4)
Hello @rajani007.
I've tried to reproduce the issue using java-jwt 2.2.1
and a key pair generated with openssl:
- Generate private key. I used the password "secret".
openssl genrsa -des3 -out private.pem 2048
- Get private key in PEM format
openssl rsa -in private.pem -out private_unencrypted.pem -outform PEM
- Get public key also in PEM format
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Outputs for 2 and 3:
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAv96lCis0QPEB7sHRiZ5mHAlFrjuiUuKk3Lmt76cbwX21SF5c
40PT50BC9ZJgfj834pvOut0dNcMF/dzQ80uCyUwL3NjGR+SxUkJ0J9sKFeZLNwS5
zrJi9HB5DeDXw3jTnMvOxIMMzSpf1KoQtyw703qVNw6nfSyywjtLUbCWKvPuKSG/
l3bbSPX+vdqb5NmDlA+afUa00FaxL9vBh49F8K+WZSsnE5xl94yXfEczScmihlxg
GJUz2KTU3LM9Afwv7O0iBEo9yLnLgQZT+SdmbbO9Sjb7KfhAOgjF71pZaZl6zm2X
A9fRlj9zHaY0uYwtQqXPRIGd79ZSi2Yfmi0lhwIDAQABAoIBACrv3isaZAUsaexO
P1/2rI8VnBxTiA3YXmBuxPfeg52XThw10b+iDCex/8oIycM2zoDNsUOr+79uN0cK
RVBM06XMeNMhR64LBYuNB4VrxSQFd0uGqTYSQYbGLLDoYiCCR4jNKyZa1WCMXQmw
TTFQmsrGoeHCS8T9XbuNnVtYkyJlNLGVayamYksvjegQFqXlXDjeE0UtxK8r0K0G
9YwKObezfbol99V6JwImKCiQ8iCO0UQjsy1qxJCQsJTnmaJV/Px3tFA/cP6RF320
DXLi8tmStiJWxGOXvHDdVIBDS/J7uBMEx7Qv5AZIdQ48ayuujyu63R1hnWItKPm5
T7fWQlECgYEA7iMogob2X8c3oeSP681NkKCjjQHoX6slffalIUra9wS5nM/9QepA
grhHidP1A2ZV4hp6Cz04Qaq6/AyX15iYU9dPcm+YGSGh3AuSzbW+5AxIn/NoqG9U
zNqXyj17MZotZPV8DyYrm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ihlxgGJUz2KTU3LM9Afwv7O0iBEo9yLnLgQZT+Sdm
bbO9Sjb7KfhAOgjF71pZaZl6zm2XA9fRlj9zHaY0uYwtQqXPRIGd79ZSi2Yfmi0l
hwIDAQAB
-----END PUBLIC KEY-----
I signed some claims using the private key:
JWTSigner signer = new JWTSigner(getPrivateKey());
HashMap<String, Object> claims = new HashMap<String, Object>();
claims.put("sub", "1234567890");
claims.put("name", "John Doe");
claims.put("admin", "true");
JWTSigner.Options options = new JWTSigner.Options();
options.setAlgorithm(Algorithm.RS256);
String jwtSigned = signer.sign(claims, options);
System.out.println("Signed: " + jwtSigned);
//Prints: Signed: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOiJ0cnVlIn0.dzAYYUAZtGuQYscPAQ2XZLq15ijlNSYml7CS12Ek_Byah2ENgUnjuHgBLWhGtUJHXBbb6EpqHbgr5gtSiJN1liLBHTnK28EpwsJAiKWN4TEyIkMfI3VTzg1WoKsJnvVPoH0INbcMwNAZSF_E5KDlrBbD73l1c8IPaWOBQG3hbW9iF6WkdgX6_FanYrnL4ULfVmZ2D2WY16W8Ewo0ycU42Si-ErOkHyNX2592mtdMHBi_mHIi5fHuiVN8adwMcu1AdltRfrzQDSTpAd_5yqzSJ9e6K4DYh22Rzx4kWqZ-ZVWFk2RRb3wlXtJaV4xpbjKJj2TXBSPt_rtNCrQXf-TPtg
After that, I verify the output using the public key.
JWTVerifier verifier = new JWTVerifier(getPublicKey());
try {
verifier.verify(jwtSigned);
System.out.println("Verify ok!");
} catch (Exception e) {
System.out.println("Verify fail!");
e.printStackTrace();
}
//Prints: Verify ok!
The verification also passes on the http://jwt.io site, so I guess it's something related to how you generate the keys or how you read the file.
Also if this is an option for you guys @rajani007 @tyy10002, I recommend you to move to the latest version (currently 3.0.2).
Cheers.
from java-jwt.
I have a similar issue. I generated a jwt in java with ES256. Then, I have other node applications using hapi-jwt plugin, and I got this error [TypeError: "ES256" signatures must be "64" bytes, saw "72"].
from java-jwt.
Hi,
Thanks for trying. I should have updated here saying that i was able to make it work with simple fix as suggested here.
from java-jwt.
@rajani007 I'm glad you could resolve it! 😄
from java-jwt.
Related Issues (20)
- Published license identifier is not compliant with the SPDX license list HOT 2
- com.auth0.jwt.exceptions.JWTDecodeException: The input is not a valid base 64 encoded string. HOT 6
- Allow configuration of Jackson ObjectMapper HOT 2
- token is still alive, when "exp" = NOW HOT 2
- Support for the absence of payload HOT 4
- Add Support for the EdDSA Signatures HOT 2
- Support for PS256 algorithm HOT 2
- Integrating java-jwt into OSS-Fuzz HOT 2
- Aud with empty string returns empty List HOT 7
- Allow using custom ObjectMapper for JWTParser HOT 2
- Does the lib have a feature to create jwt token from pem file? HOT 1
- From 3.19.4 to 4.4.0: IncorrectClaimException on verify() HOT 5
- KeyProvider-style API for signature schemes (HMAC) HOT 2
- NullPointerException when checking empty audience HOT 2
- Javadoc contains dead links to readme HOT 1
- JwkProviderBuilder doesn't allow us to load jwks from a file. Instead the only option available is to load it via a URL. HOT 1
- IncorrectClaimException
- Invalid Token: The token can't be used before 2024-04-29T04:27:39Z
- Wrong algorithm name matching between JWT and Algorithm HOT 1
- It is suspected that the interface definition is incorrect
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 java-jwt.