0

I create asymmetric key pair via RSACryptoServiceProvider . I get the key pair in byte[], so it can be saved. I'm avoiding the XML option, in order to avoid possible cross-platform encoding issues.

        public byte[] CreateKeyPair()
    {
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

        //read the key pair in byte[]
        RSAParameters rsaKeyPair = rsa.ExportParameters(true);
        List<byte> keyPairList = new List<byte>();
        foreach (byte b in rsaKeyPair.D) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.DP) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.DQ) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.Exponent) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.InverseQ) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.Modulus) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.P) { keyPairList.Add(b); }
        foreach (byte b in rsaKeyPair.Q) { keyPairList.Add(b); }

        return keyPairList.ToArray();
    }

now I want to convert from byte[] back to RSACryptoServiceProvider.

My question is, are all the fields of fixed size every time, and if so what size is each field, or should I delimit those somehow?

What if I serialize RSAParameters , will someone be able to easily deserialize/read the struct in C++? I think not, but worth asking anyway...

0 Answers0