Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provided private key could not be used to sign JWT #99

Open
Ginso opened this issue Apr 12, 2021 · 1 comment
Open

Provided private key could not be used to sign JWT #99

Ginso opened this issue Apr 12, 2021 · 1 comment

Comments

@Ginso
Copy link

Ginso commented Apr 12, 2021

Hello,
i tried creating a JWT with the following code from your documentation:

let path = Bundle.main.path(forResource: "privateKey", ofType: "key")
let privateKeyPath = URL(fileURLWithPath: path!)
let privateKey: Data = try Data(contentsOf: privateKeyPath, options: .alwaysMapped)
let jwtSigner = JWTSigner.rs256(privateKey: privateKey)
let signedJwt = try jwt.sign(using: jwtSigner)

but at the last line i get an exception telling me that the 'Provided private key could not be used to sign JWT'.
I've first tried a key that has always worked in java and then a key generated with
ssh-keygen -t rsa -b 4096 -m PEM -f privateKey.key
The second one is much longer, but both keys produce the same result.

@mbarnach
Copy link
Member

Is it working with an on-the-fly key generation, like that:

let privateKey = try ECPrivateKey.make(for: .prime256v1)
let privateKeyPEM = privateKey.pemString
let jwtSigner = JWTSigner.es256(privateKey: Data(privateKeyPEM.utf8)
let signedJwt = try jwt.sign(using: jwtSigner)

This is a different type of key, but it shouldn't matter for the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants