1

We have this business case where our c# web app will generate a public/private key pair for a corresponding iOS mobile device. The mobile device will use the public key to encrypt data and send it back up to the server.

I am using the following c# code.

        const int PROVIDER_RSA_FULL = 1;
        const string CONTAINER_NAME = "KeyContainer";
        CspParameters cspParams;
        cspParams = new CspParameters(PROVIDER_RSA_FULL);
        cspParams.KeyContainerName = CONTAINER_NAME;
        cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
        cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
        var rsa = new RSACryptoServiceProvider(2048,cspParams);
        rsa.PersistKeyInCsp = false;
        string publicPrivateKeyXML = rsa.ToXmlString(true);

After that, I don't know how to get the rsa.ToXmlString to the iOS app in a format it can support with the objective-c Crypto Libraries. How can I covert that public key (modulus +exponent) WITHOUT using OpenSSL to something iOS will understand and encrypt data with. This key generation will happen a lot (not once), and any new library has to approved before use. So answers that don't require additional libraries are favored.

Josh
  • 2,248
  • 2
  • 19
  • 38
  • The XML output is pretty self-explanatory. I'm not familiar with iOS but I'm sure there are base64 libraries that can help you decode the XML. – President James K. Polk Jan 17 '13 at 00:31
  • It is, objective-c isn't. It wants a certificate file or you to generate it on the device so it stores it securely. .Net you have all the components. objective-c, not so much. I'm talking about the built in crypto library though. – Josh Jan 17 '13 at 13:09
  • was this ever resolved? i am looking to do the same – Julien Jul 22 '13 at 14:32
  • We ended up going with a third party iOS component that had a few other features we needed. It also allowed us to import a key with the separate elements or multiple file types. Also we moved to xamarian which helps as well. – Josh Jul 22 '13 at 18:11

1 Answers1

0

Please use this C# from this ref, this class will generate public and private RSA key in SSh pem style:

Sample class

Trí Chồn
  • 617
  • 8
  • 15