S
Sygnosys
Hi,
I have a piece of code in .NET that encrypts a string.
The .NET code is quite simple and through the last couple of days I've
been trying to build it's equivalent in ATL playing arround with CCrypt
classes and I just haven't been able to get it right.
So if anyone can help me porting this to ATL or Win32 I would be
grateful.
..NET Code:
String* Encrypt(String* PlainText)
{
System::Byte IV[] = { 1, 9, 1, 7, 1, 4, 6, 4 };
System::Byte key[] = Convert::FromBase64String("password");
TripleDES *algorithm = TripleDESCryptoServiceProvider::Create();
MemoryStream *memStream = new MemoryStream();
CryptoStream *cryptoStream = new CryptoStream( memStream,
algorithm->CreateEncryptor( key, IV ),CryptoStreamMode::Write );
StreamWriter* myWriter = new StreamWriter(cryptoStream);
myWriter->Write(PlainText);
myWriter->Flush();
cryptoStream->FlushFinalBlock();
memStream->Flush();
String *strResult =
Convert::ToBase64String(memStream->GetBuffer(),0,(int)memStream->get_Length());
return strResult;
}
I have a piece of code in .NET that encrypts a string.
The .NET code is quite simple and through the last couple of days I've
been trying to build it's equivalent in ATL playing arround with CCrypt
classes and I just haven't been able to get it right.
So if anyone can help me porting this to ATL or Win32 I would be
grateful.
..NET Code:
String* Encrypt(String* PlainText)
{
System::Byte IV[] = { 1, 9, 1, 7, 1, 4, 6, 4 };
System::Byte key[] = Convert::FromBase64String("password");
TripleDES *algorithm = TripleDESCryptoServiceProvider::Create();
MemoryStream *memStream = new MemoryStream();
CryptoStream *cryptoStream = new CryptoStream( memStream,
algorithm->CreateEncryptor( key, IV ),CryptoStreamMode::Write );
StreamWriter* myWriter = new StreamWriter(cryptoStream);
myWriter->Write(PlainText);
myWriter->Flush();
cryptoStream->FlushFinalBlock();
memStream->Flush();
String *strResult =
Convert::ToBase64String(memStream->GetBuffer(),0,(int)memStream->get_Length());
return strResult;
}