I'm trying to initialize RSACryptoServiceProvider with my own public and private keys.
As far as I could research, the way to do this is to call the constructor with
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);
cspParams as shown above. However, when I look at the msdn example on the use of it: http://msdn.microsoft.com/en-us/library/ca5htw4f.aspx
I don't see any place where they set the private or public keys. Only using a KeyContainer. When I create an RSACryptoServiceProvider without a cspParam, then it is by default set to only use a Public key. I notice this when I check the PublicOnly variable on the class itself and it is a read only variable.
My question is how do I initialize this class and then set my own private and public keys. The server will be using the private key and the client will have the public key.
What I found out is that creating an RSAParameter object and setting the .Exponent and .Modulus parameters on it as the public and private variables respectively.
But I'm getting a "Missing Private Key" error since I believe the RSACryptoServiceProvider isn't initialized with the correct constructor.
Below is some of my code. Don't worry about BigInteger class, it's just an experiment. Even if I use it or not, I get the same error.
//Create a UnicodeEncoder to convert between byte array and string.
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes(password);
byte[] encryptedData;
byte[] decryptedData;
//RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters rsap = new RSAParameters();
BigInteger n = new BigInteger("19579160939939334264971282204525611731944172893619019759209712156289528980860378672033164235760825723282900348193871