开发者

RSA iphone public key

开发者 https://www.devze.com 2023-01-25 20:09 出处:网络
I have a Public Key generated in JAVA. I want to use this key and crypt the data using RSA and send 开发者_开发知识库it to the server.

I have a Public Key generated in JAVA. I want to use this key and crypt the data using RSA and send 开发者_开发知识库it to the server. How can I do that using the iPhone SDK?

Thanks


Unfortunately, iOS has no public APIs to deal with raw RSA keys.

There are two things you can do:

1) Instead of giving your app a Public Key, give your app a certificate instead. You can import the certificate with SecCertificateCreateWithData. Then create a trust with SecTrustCreateWithCertificates. Once you have the trust, you can extract the public key with SecTrustCopyPublicKey.

2) The other option is to include OpenSSL in your project. It has all the APIs you need, you can google for example code on how to work with RSA keys. This might be the simpler solution.

I have made available a script to easily build OpenSSL from source. You can grab it from:

http://github.com/st3fan/ios-openssl


If your public key is in modulus/exponent form, this question may help: Convert XML Dsig format to DER ASN.1 public key

I figured out how to binary-encode the modulus and exponent into the DER ASN.1 format that the SecKeyWrapper class of Apple's CryptoExercise project uses to import an external key.

0

精彩评论

暂无评论...
验证码 换一张
取 消