gpt4 book ai didi

ios - 在 iOS 上使用 RSA 公钥

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:49 24 4
gpt4 key购买 nike

我正在开发一个应用程序,我将从我们的服务器检索用户的公钥。获得它后,我需要使用公钥进行 RSA 加密。从服务器获取的公钥是Base64编码的。

如何将公钥加载到 iOS KeyChain 中,以便我可以使用它执行 RSA 加密功能?证书加载似乎是微不足道的,但原始公钥却并非如此。

最佳答案

这不受支持,因为它是"wrong"方式

正确”的方法是使用 a certificate .

收件人quote "Quinn The Eskimo!" .

This is surprisingly easy. You don't need to add the certificate to the keychain to handle this case. Rather, just load the certificate data (that is, the contents of a .cer file) in your application (you can either get this from your bundle or off the network) and then create a certificate ref using SecCertificateCreateWithData. From there you can extract a public key ref using a SecTrust object (SecTrustCreateWithCertificates, SecTrustEvaluate -- you can choose to ignore the resulting SecTrustResultType -- and SecTrustCopyPublicKey). And from there you can encrypt and verify using the SecKey APIs (SecKeyEncrypt, SecKeyRawVerify).

关于 how to create a self-signed certificate is here 的教程.

基本步骤是:

#Make the -----RSA PRIVATE KEY----- file in PEM format
openssl genrsa -out privKey.pem 2048

#Make the -----CERTIFICATE REQUEST-----
openssl req -new -key privKey.pem -out certReq.pem

#Make the actual -----CERTIFICATE-----
openssl x509 -req -days 30 -in certReq.pem -signkey privKey.pem -out certificate.pem

#Make the DER certificate.crt file from the certificate.pem
openssl x509 -outform der -in certificate.pem -out certificate.cer

如果您在 Mac 机器上双击 .cer,它会提示将其导入钥匙串(keychain)。

资源:

关于ios - 在 iOS 上使用 RSA 公钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com