我在 Cocoa 环境中解密 RSA 公钥时遇到问题。
我已使用 -----BEGIN PUBLIC KEY-----
防护(由 openssl 生成)
NSData *encryptedData = base64dec(license);
NSString *publicKeyPath = [[NSBundle mainBundle] pathForResource:@"public" ofType:@"pem"];
NSData *publicKeyData = [NSData dataWithContentsOfFile:publicKeyPath];
SSCrypto *crypto = [[SSCrypto alloc] initWithPublicKey:publicKeyData];
[crypto setClearTextWithData:encryptedData];
[crypto verify];
NSString *verifiedKey = [crypto clearTextAsString];
但是verifiedKey
始终为零。看起来 SSCrypto 无法将 NSData 转换为 NSString。我怎样才能真正解密数据?
最终使用此代码(以消除 Base64 解码步骤)
[crypto setCipherTextFromBase64String:license];
NSString *verifiedKey = [crypto clearTextAsString];
但是verifiedKey
始终是空字符串。这是什么意思?输入数据似乎是正确的。
最佳答案
由于您要解密加密数据,因此应该执行 setCipherText: 而不是 setClearTextWithData:
此外,调用 verify 而不使用其返回值没有任何意义。
关于objective-c - 解密Cocoa中的RSA公钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15042529/