yourkarma / JWT

A JSON Web Token implementation in Objective-C.
MIT License
350 stars 107 forks source link

Encode with RS256 using string data of a private key #203

Closed dittmarconsulting closed 5 years ago

dittmarconsulting commented 5 years ago

New Issue Checklist

Issue Info

Info Value
Platform Name ios
Platform Version 11.4
CocoaLumberjack Version N/A
Integration Method carthage
Xcode Version 9.4.1
Repro rate N/A
Demo project link N/A

Issue Description and Steps

I have simply copied the example code:

NSDictionary *payload = @{@"payload" : @"hidden_information"};
NSString *algorithmName = @"RS256";

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"secret_key" ofType:@"p12"];
NSData *privateKeySecretData = [NSData dataWithContentsOfFile:filePath];

NSString *passphraseForPrivateKey = @"secret";

JWTBuilder *builder = [JWTBuilder encodePayload:payload].secretData(privateKeySecretData).privateKeyCertificatePassphrase(passphraseForPrivateKey).algorithmName(algorithmName);
NSString *token = builder.encode;

Instead of having a p12 file I have a sting of a secret key. Something like that:

"-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAtN7LQq7l9a9....SUug==\n-----END RSA PRIVATE KEY-----\n"

Is there a way to implement the string with this library?

Thanks in advance.

dittmarconsulting commented 5 years ago

Found the solution https://stackoverflow.com/questions/52464995/objective-c-jwt-encode-with-rs256-using-string-data-of-a-private-key/52624479#52624479

sambo-nbc commented 2 years ago

Found the solution https://stackoverflow.com/questions/52464995/objective-c-jwt-encode-with-rs256-using-string-data-of-a-private-key/52624479#52624479

Hi! I have the same issue as you. and I followed instructions in the link above and got this error. Could you help me please? how did you make it successful? [seckey] SecKeyCreate init(RSAPrivateKey) failed: -50