我正在使用这个库来编码 RS256
token https://github.com/yourkarma/JWT
在文档中有一个处理 RS256
编码的示例
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;
现在,因为我只有一串类似这样的私钥:
"-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAtN7LQq7l9a9....SUug==\n-----END RSA PRIVATE KEY-----\n"
我想知道如何实现它?显然我不需要密码。
提前致谢
在同事的帮助下,事实证明这并不难 ;-)
解决办法如下:
NSDictionary *payload = @{@"payload" : @"hidden_information"};
id <JWTAlgorithmDataHolderProtocol> holder = [JWTAlgorithmRSFamilyDataHolder new]
.keyExtractorType([JWTCryptoKeyExtractor privateKeyWithPEMBase64].type)
.privateKeyCertificatePassphrase(nil)
.algorithmName(JWTAlgorithmNameRS256)
.secret(<string of the private key as above>);
JWTCodingResultType *result = [JWTEncodingBuilder encodePayload:payload]
.addHolder(holder)
.result;
NSString *token = result.successResult.encoded;
NSError *error = result.errorResult.error;
关于ios - Objective-C:JWT - 使用私钥的字符串数据使用 RS256 进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52464995/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |