Hi guys,
I've been struggling for 2 months now trying to get RSA encryption to work on iOS and I feel that I'm missing some key pieces here and wondered if anyone can help clarify a few things for me. (I've never had to deal with encryption before so some of the stuff I say could be very incorrect.) My goal is to break this down into pieces and research and solve each piece.
My application has access to a modulus and an exponent which apparently together make the public key. It is to take these and use them to encrypt JSON data to be sent to a web server which holds the private key.
Apples documentation (and other places) show this being done with certificates, our app doesn't use certificates and instead just generates the encrypted data, which leads to:
Question 1: Is this the wrong way to do things? I'm not sure what the certificates actually do in these cases. Should I be using certificates instead of having the application have a modulus and exponent hardcoded?
Question 2: Here are the steps I think I need to solve in order for this to work. Can someone let me know if this is correct?
1. Generate a public key based on the modulus and exponent. (I'm not sure how to do this, people say use OpenSSL, Apple says don't use OpenSSL, I don't even know how I'd use OpenSSL from within my code).
2. Store that key in the iPhone/iPad keychain (It appears that you have to store them as a certificate, is that true?).
3. Use the SecKeyEncrypt functions to encrypt the JSON data (which appears to have to be converted to plaintext first).
4. Encode the encrypted data to base 16 which the web service expects.
If anyone has any tips, tricks, code samples, videos, book titles etc on how to do any parts of this it would be greatly appreciated. I have scoured Apples documents, Stack Overflow, GitHub, etc and nothing I have found seems to fully work. Thank you for any help you can provide.
I've been struggling for 2 months now trying to get RSA encryption to work on iOS and I feel that I'm missing some key pieces here and wondered if anyone can help clarify a few things for me. (I've never had to deal with encryption before so some of the stuff I say could be very incorrect.) My goal is to break this down into pieces and research and solve each piece.
My application has access to a modulus and an exponent which apparently together make the public key. It is to take these and use them to encrypt JSON data to be sent to a web server which holds the private key.
Apples documentation (and other places) show this being done with certificates, our app doesn't use certificates and instead just generates the encrypted data, which leads to:
Question 1: Is this the wrong way to do things? I'm not sure what the certificates actually do in these cases. Should I be using certificates instead of having the application have a modulus and exponent hardcoded?
Question 2: Here are the steps I think I need to solve in order for this to work. Can someone let me know if this is correct?
1. Generate a public key based on the modulus and exponent. (I'm not sure how to do this, people say use OpenSSL, Apple says don't use OpenSSL, I don't even know how I'd use OpenSSL from within my code).
2. Store that key in the iPhone/iPad keychain (It appears that you have to store them as a certificate, is that true?).
3. Use the SecKeyEncrypt functions to encrypt the JSON data (which appears to have to be converted to plaintext first).
4. Encode the encrypted data to base 16 which the web service expects.
If anyone has any tips, tricks, code samples, videos, book titles etc on how to do any parts of this it would be greatly appreciated. I have scoured Apples documents, Stack Overflow, GitHub, etc and nothing I have found seems to fully work. Thank you for any help you can provide.