Using RSA Public Key in iOS

I am working on an application in which I will get the public key for the user from our server. Once I have this, I need to do RSA encryption using the public key. The public key received from the server is Base64 encoded.

How to load a public key in iOS KeyChain so that I can perform RSA cryptographic functions with it? Downloading the certificate seems trivial, but the original public keys do not.

+2
source share
3 answers

I found the necessary code on the Apple website that describes how to remove the ASN.1 header from the public key and upload it to KeyChain.

0
source

, "" .

" right" .

"Quinn The Eskimo!" .

. . ( .cer) ( ), SecCertificateCreateWithData. ref, SecTrust (SecTrustCreateWithCertificates, SecTrustEvaluate - SecTrustResultType - SecTrustCopyPublicKey). SecKey API (SecKeyEncrypt, SecKeyRawVerify).

, .

:

#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

.cer Mac, .

+4

The usual way to transport a public key is inside a certificate signed by a certificate authority to prove that it is genuine.

Or maybe you're talking about the ssh public key? in this case, you will need a special ssh application to use them, these keys are usually not stored in the iOS keychain.

+1
source

All Articles