This question already has an answer here:
- RSA Encryption public key? 1 answer
I have modulus and exponent. How can I encode/decode data with RSA algotithm on iPhone? Or how can I generate DER format from modulus and exponent?
This question already has an answer here:
I have modulus and exponent. How can I encode/decode data with RSA algotithm on iPhone? Or how can I generate DER format from modulus and exponent?
If you want to generate DER data on the iPhone, I have code on GitHub that will let you do this:
https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS
SCZ-BasicEncodingRules-iOS
Implementation of Basic Encoding Rules to enable import of RSA keys to iOS KeyChain using exponent. Code targets iOS 5 with ARC.
Let's say you already have a modulus and exponent from an RSA public key as an NSData in variables named pubKeyModData and pubKeyModData. Then the following code will create an NSData containing that RSA public key, which you can then insert into the iOS or OS X Keychain.
This would allow you to store the key using the addPeerPublicKey:keyBits: method from SecKeyWrapper in the Apple CryptoExercise example. Or, from the perspective of the low-level API, you can use SecItemAdd().