用iphone中的公钥解密
我有一个公钥和一个加密字符串。我可以成功地使用公钥加密。但是当我尝试使用公钥解密时,它失败了。我的意思是,当我将公钥传递给seckeyDecrypt时,它失败了。
我用 Google 搜索发现,默认情况下 kSecAttrCanDecrypt 对于公钥来说是 false。所以当我导入公钥时,我添加了这一特定行,
[publicKeyAttr setObject:(id)kCFBooleanTrue forKey:(id)kSecAttrCanDecrypt];
但是没有任何改进,它仍然失败。请有人帮忙。
编辑: Apple 的证书、密钥和信任服务表示,
kSecAttrCanEncrypt 私钥默认为 false,公钥默认为 true。
kSecAttrCanDecrypt 私钥默认为 true,公钥默认为 false。
这意味着,这些值可以改变,对吧?我的服务器不签署(转换为摘要)内容。他们只是使用私钥进行加密,私钥将在我的(iPhone 中)端解密。这可能吗?
I have a public key and an encrypted string. I could encrypt with the publickey successfully.But when i try to decrypt using the publickey it fails. I mean when i pass the publickey toseckeyDecrypt it fails.
I have Googled and found out that, by default kSecAttrCanDecrypt is false for public keys.So When i import the public key, i have added this particular line ,
[publicKeyAttr setObject:(id)kCFBooleanTrue forKey:(id)kSecAttrCanDecrypt];
But there is no improvement it still fails. Please somebody help.
EDIT:
Apple's Certificate,Key and Trust Services Says,
kSecAttrCanEncrypt Default false for private keys, true for public keys.
kSecAttrCanDecrypt Default true for private keys, false for public keys.
Which means, the values can be changed right?. My server does not sign(Convert as a digest) the content. They just encrypt using the private key which is to be decrypted at my(in iphone) end. Is that possible?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非对称加密的要点是使用公钥加密并使用私钥解密。
编辑:如果您要签名和验证,则应使用关联的 API。例如,您可以使用
kSecAttrCanSign
和kSecAttrCanVerify
检查此功能。The point of asymmetric cryptography is that you encrypt with the public key and decrypt with the private key.
EDIT: If you're signing and verifying, you should use the associated APIs. For example, you can check this capability with
kSecAttrCanSign
andkSecAttrCanVerify
.