From: Steelx on
i am having a very tough time figuring out how to encrypt something in
c# and then decrypt it in c++ using cryptography (and vice versa). i
am at a lose. there seems to be no corralation between the old api and
the new .net implementation. any help will be appreciated. any
example of even the simplist encryption that can implemented cross
platform (c++ and c#) would be very helpful.

what i have written in c++

CryptAcquireContext(&hMyCryptProv, NULL, MS_ENHANCED_PROV,
PROV_RSA_FULL, CRYPT_NEWKEYSET);
CryptCreateHash(hMyCryptProv, CALG_MD5, 0, 0, &hHash);
CryptHashData(hHash, (BYTE *)szBaseData, strlen(szBaseData), 0); //hash
base data
CryptDeriveKey(hMyCryptProv, CALG_RC4, hHash, 0x00800000, &hKey);
//create key
CryptEncrypt(hKey, 0, true, 0, NULL, &dwActualDataLen, lLen);
//compute the length
pBuf = (void *)LocalAlloc(LPTR, dwActualDataLen); //allocate memory
for it
memcpy((void *)pBuf, pvData, lLen); //load mem with data to be
encrypted
dwActualDataLen = lLen;
CryptEncrypt(hKey, 0, true, 0, (BYTE *)pBuf, &dwActualDataLen, lLen);
//encrypt it


what is the equivilent in c# ??? here is what i have experimented
with. nothing solid at all.

//md5 the base data
System.Security.Cryptography.MD5CryptoServiceProvider oMD5 = new
MD5CryptoServiceProvider();
byte[] buffer = oMD5.ComputeHash(StringToByteArray(BaseData));

System.Security.Cryptography.CspParameters csp = new
CspParameters(1,"Microsoft Enhanced Cryptographic Provider v1.0",null);
csp.KeyNumber = 2;
csp.Flags = CspProviderFlags.UseDefaultKeyContainer; //
UseDefaultKeyContainer;

//make a key from the hashed base data??
//System.Security.Cryptography.PasswordDeriveBytes pdb = new
PasswordDeriveBytes(BaseData,null);
//byte[] ivZeros = new byte[8];
//byte[] pbeKey = pdb.CryptDeriveKey("CALG_RC4", "MD5", 128, ivZeros);

//i am at a lose. there seems to be no corralation between the old api
and the new .net implementation.
System.Security.Cryptography.RSACryptoServiceProvider RSACrypt = new
RSACryptoServiceProvider(csp);
byte [] abc = RSACrypt.SignHash(buffer, "this is my password");

byte[] buffer2 = RSACrypt.Encrypt(StringToByteArray("this is my
password"),true);




any help will be appreciated.
JT

From: Tom St Denis on

Steelx(a)gmail.com wrote:
> i am having a very tough time figuring out how to encrypt something in
> c# and then decrypt it in c++ using cryptography (and vice versa). i
> am at a lose. there seems to be no corralation between the old api and
> the new .net implementation. any help will be appreciated. any
> example of even the simplist encryption that can implemented cross
> platform (c++ and c#) would be very helpful.

I'll tell you what I tell all others asking the same question. e-mail
the library provider and ask for assistance.

Tom

From: rossum on
On 3 Oct 2006 12:58:13 -0700, Steelx(a)gmail.com wrote:

>i am having a very tough time figuring out how to encrypt something in
>c# and then decrypt it in c++ using cryptography (and vice versa). i
>am at a lose. there seems to be no corralation between the old api and
>the new .net implementation. any help will be appreciated. any
>example of even the simplist encryption that can implemented cross
>platform (c++ and c#) would be very helpful.

1 Try asking in C++ and C# newsgroups as well.

2 Explain exactly what you are trying to do at each end in english as
well as posting code.

3 Try to get something very simple working at each end first. For
instance take a single block "abcdefghijklmnop" and encrypt it in
AES-ECB mode with a 128-bit key: "0123456789ABCDEF". Decrypt it in
the other language. No padding, no password processing, no IV, no
Nonce just really basic encryption and decryption. Get this working
in both directions first. Then add the extra complications that you
need one by one. Don't try to do everything all at once but work up
to it in steps.

rossum

From: Unruh on
rossum <rossum48(a)coldmail.com> writes:

>On 3 Oct 2006 12:58:13 -0700, Steelx(a)gmail.com wrote:

>>i am having a very tough time figuring out how to encrypt something in
>>c# and then decrypt it in c++ using cryptography (and vice versa). i
>>am at a lose. there seems to be no corralation between the old api and
>>the new .net implementation. any help will be appreciated. any
>>example of even the simplist encryption that can implemented cross
>>platform (c++ and c#) would be very helpful.

Agreed with below, but you are not very clear. Are you using a canned AES
subroutine or library? If yes, which one, and do you know how to link to
libraries in both of those languages? If you are writing your own, test
each and every subroutine first to make sure you know what it is doing and
that it is doing exactly the same thing in both languages.

What old api? For what? What "new .net" implimentation? From where?



>1 Try asking in C++ and C# newsgroups as well.

>2 Explain exactly what you are trying to do at each end in english as
>well as posting code.

>3 Try to get something very simple working at each end first. For
>instance take a single block "abcdefghijklmnop" and encrypt it in
>AES-ECB mode with a 128-bit key: "0123456789ABCDEF". Decrypt it in
>the other language. No padding, no password processing, no IV, no
>Nonce just really basic encryption and decryption. Get this working
>in both directions first. Then add the extra complications that you
>need one by one. Don't try to do everything all at once but work up
>to it in steps.

>rossum