objective-c - 解密Cocoa中的RSA公钥

标签 objective-c cocoa openssl

我在 Cocoa 环境中解密 RSA 公钥时遇到问题。 我已使用 -----BEGIN PUBLIC KEY----- 防护(由 openssl 生成)

加密了 public.pem 中的哈希值和公钥

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/

相关文章:

iOS:存储在 session 中过期的 cookie

cocoa - 10.9 替换 [NSFont systemFontOfSize : weight:]

objective-c - NSVisualEffectView 上的 NSScrollView/NSCollectionView 导致闪烁

python - 在Python中转换Cocoa时间戳

php - 带有 PHP 5.6 和 Composer 的 OpenSSL - 证书验证失败

ssl - openSSL 如何使用 SHA256 签署证书

ios - 重构 Storyboard时如何交换标签栏项目的位置

objective-c - 覆盖 layoutSubViews : causes "CGAffineTransformInvert: singular matrix" randomly

objective-c - NSTableView 内的 NSButtonCell 复选框始终获取 NSOffState。为什么?

linux - OpenSSL 以静态方式链接 libcrypto.a