Below I've mentioend the steps for both C++ and .net code ..please let me
know any other information is required.
-----C++ code---
1.CryptAcquireContext(&hCryptProv, NULL, MS_DEF_RSA_SCHANNEL_PROV,
PROV_RSA_SCHANNEL,CRYPT_MACHINE_KEYSET)
2.CryptGenKey(hCryptProv, CALG_RSA_KEYX , CRYPT_EXPORTABLE, &hKey)
3.CryptExportKey(hKey, NULL, PUBLICKEYBLOB, 0, NULL, &dwPublicKeyLen)
4.(hPublicKeyFile = CreateFile(_T("c:\\temp\\sPublicKey.txt"),
GENERIC_WRITE,0,NULL,CREATE_ALWAYS, NULL,NULL)
5. WriteFile(hPublicKeyFile, (LPCVOID)pbPublicKey, dwPublicKeyLen,
&lpNumberOfBytesWritten,NULL )
6.Similarly PRIVATEKEY is also generated and written to a file.
---.net code----
const int PROV_RSA_SCHANNEL = 12;
const string CONTAINER_NAME = "";//"Interealty is our home.";
CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft RSA SChannel Cryptographic Provider";
cspParams.KeyNumber = 1;
cspParams.ProviderType = 12;
rsa = new RSACryptoServiceProvider(cspParams);
FileStream fs = new FileStream(@"c:\\temp\\encry.txt", FileMode.Open,
FileAccess.Read);
byte[] ImageData = new byte[fs.Length];
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
StreamReader reader = new StreamReader(@"c:\\temp\\sPublicKey.txt");
string publicPrivateKeyXML = reader.ReadToEnd();
byte[] priData =
System.Text.UnicodeEncoding.Unicode.GetBytes(publicPrivateKeyXML);
rsa.ImportCspBlob(priData ); ** Here I'm getting the error as "Bad
Version of provider"