Cross Platform encryption/decryption

  • Thread starter Thread starter shamsh
  • Start date Start date
S

shamsh

I have a COM object written in VC++ which has encryption code.I would like to
decrypt the string which was generated by COM.
COM is using RSA and cryptoAPIs for encryption and .net will have to use the
RSACryptoServiceprovider.
Cab anyone let me know how to achieve the decryption in .Net?
 
Shamsheer,

Have you looked at the System.Security.Cryptography.RSA and
System.Security.Cryptography.RSACryptoServiceProvider classes?
 
shamsh said:
I have a COM object written in VC++ which has encryption code.I would like to
decrypt the string which was generated by COM.
COM is using RSA and cryptoAPIs for encryption and .net will have to use the
RSACryptoServiceprovider.
Cab anyone let me know how to achieve the decryption in .Net?

RSA is a well defined standard and .NET supports RSA so it should
be doable.

Based on the level of details provided, then that is about what we
can say.

Arne
 
yes i did and using the same...but while trying to import the keys in
..net(using ImportCspBlob) it is giving error as "bad version of provider".
--
regards,
Shamsheer


Nicholas Paldino said:
Shamsheer,

Have you looked at the System.Security.Cryptography.RSA and
System.Security.Cryptography.RSACryptoServiceProvider classes?
 
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"
 
Back
Top