V
vcnewbie
Hi
I'm maintaining a VisualC++ project to increase its security regarding
stored passwords.
I thought about using SHA256Managed to create a hash for the password
when creating a user and when this new user tries to login, a new hash
will be created for the given password and compared to the stored
hash. I guess this is quite common.
My problem is that I'm not used (at all) with the 2005 edition (just
VC6) and the creator of the software uses extensively managed strings,
i.e.:
String ^ SomeName
And I'm in trouble converting this type to what SHA256Managed can
understand and then convert the hash back to "String^"
This is what I've found, just for testing the conversion techniques:
#include "stdafx.h"
using namespace System;
using namespace System::Text;
using namespace System::Security::Cryptography;
int main()
{
// Create two different encodings.
Encoding^ ascii = Encoding::ASCII;
Encoding^ unicode = Encoding::Unicode;
String ^ sSourceData = "operator";
// Perform the conversion from one encoding to the other.
ascii, UnicodeData );
SHA256^ shaM = gcnew SHA256Managed;
ascii->GetChars( result, 0, HashResult ->Length, asciiChars,
0 );
String ^ sOutputData = gcnew String( asciiChars );
Console::WriteLine( sOutputData );
}
As far as I could understand the ouput, it seems that ComputeHash is
generating real bytes and not hex digits, and I have read somewhere
(can't find it any more) that ComputeHash would generate a hex string
in the output array.
Any ideas?
Thanks in advance
Francisco
I'm maintaining a VisualC++ project to increase its security regarding
stored passwords.
I thought about using SHA256Managed to create a hash for the password
when creating a user and when this new user tries to login, a new hash
will be created for the given password and compared to the stored
hash. I guess this is quite common.
My problem is that I'm not used (at all) with the 2005 edition (just
VC6) and the creator of the software uses extensively managed strings,
i.e.:
String ^ SomeName
And I'm in trouble converting this type to what SHA256Managed can
understand and then convert the hash back to "String^"
This is what I've found, just for testing the conversion techniques:
#include "stdafx.h"
using namespace System;
using namespace System::Text;
using namespace System::Security::Cryptography;
int main()
{
// Create two different encodings.
Encoding^ ascii = Encoding::ASCII;
Encoding^ unicode = Encoding::Unicode;
String ^ sSourceData = "operator";
// Perform the conversion from one encoding to the other.
array<unsigned char>^AsciiData = Encoding::Convert( unicode,array said:GetBytes( sSourceData );
ascii, UnicodeData );
SHA256^ shaM = gcnew SHA256Managed;
Console::WriteLine(String::Format("Size: {0}", HashResult -array said:ComputeHash( AsciiData );
Length));
array said:GetCharCount( result, 0, HashResult ->Length ));
ascii->GetChars( result, 0, HashResult ->Length, asciiChars,
0 );
String ^ sOutputData = gcnew String( asciiChars );
Console::WriteLine( sOutputData );
}
As far as I could understand the ouput, it seems that ComputeHash is
generating real bytes and not hex digits, and I have read somewhere
(can't find it any more) that ComputeHash would generate a hex string
in the output array.
Any ideas?
Thanks in advance
Francisco