I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
const BYTE* sval[1];
unsigned long lval[1];
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
/**************************************/
And here is the C# code that I'm using:
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
Thanks in advance for any help I can get 6 4898
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
>
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
const BYTE* sval[1];
unsigned long lval[1];
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
/**************************************/
And here is the C# code that I'm using:
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
Thanks in advance for any help I can get
How do I go about implementing that in C#. I tried some of the various
x509 and pkcs7 classes and I kept getting exceptions having to do with
certificates and whatnot. I felt like I was wasting my time going down
the wrong path and this stuff doesn't seem too well documented on
msdn.microsoft.com.
Regards
Ben Voigt wrote:
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
const BYTE* sval[1];
unsigned long lval[1];
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
/**************************************/
And here is the C# code that I'm using:
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
Thanks in advance for any help I can get
Here is somebody's blog post that should point you in the right direction.
It's not as complicated as you indicated: http://blog.stevex.net/index.php/c-c...5-hash-string/
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ga*******@gmail.com" wrote:
How do I go about implementing that in C#. I tried some of the various
x509 and pkcs7 classes and I kept getting exceptions having to do with
certificates and whatnot. I felt like I was wasting my time going down
the wrong path and this stuff doesn't seem too well documented on
msdn.microsoft.com.
Regards
Ben Voigt wrote:
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
>
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
>
const BYTE* sval[1];
unsigned long lval[1];
>
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
>
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
>
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
>
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
>
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
>
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
>
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
>
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
>
/**************************************/
>
And here is the C# code that I'm using:
>
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
>
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
>
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
>
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
>
Thanks in advance for any help I can get
>
I've looked at that post and it's basically doing exactly what I'm
doing, The only difference is tthat the author treats the incoming
string as unicode (which mine is not. It's ascii) and he converts to
HEX (which I can't do.. I have to convert to base64 since that's how
it's stored in the database). I did try this approach and, although I
got a different hash returned, it contained the same amount number of
charectars.
I don't see any reference here to ASN.1 encoding of a PKCS #7 X.509
message. How do I go about doing this in C#?
Regards,
Gregg
Peter wrote:
Here is somebody's blog post that should point you in the right direction.
It's not as complicated as you indicated:
http://blog.stevex.net/index.php/c-c...5-hash-string/
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ga*******@gmail.com" wrote:
How do I go about implementing that in C#. I tried some of the various
x509 and pkcs7 classes and I kept getting exceptions having to do with
certificates and whatnot. I felt like I was wasting my time going down
the wrong path and this stuff doesn't seem too well documented on
msdn.microsoft.com.
Regards
Ben Voigt wrote:
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
>
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
>
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
const BYTE* sval[1];
unsigned long lval[1];
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
/**************************************/
And here is the C# code that I'm using:
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
Thanks in advance for any help I can get
Well, your original post said you were looking for an MD5 Hash. So, I guess
you are on your own.
Best of luck!
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ga*******@gmail.com" wrote:
I've looked at that post and it's basically doing exactly what I'm
doing, The only difference is tthat the author treats the incoming
string as unicode (which mine is not. It's ascii) and he converts to
HEX (which I can't do.. I have to convert to base64 since that's how
it's stored in the database). I did try this approach and, although I
got a different hash returned, it contained the same amount number of
charectars.
I don't see any reference here to ASN.1 encoding of a PKCS #7 X.509
message. How do I go about doing this in C#?
Regards,
Gregg
Peter wrote:
Here is somebody's blog post that should point you in the right direction.
It's not as complicated as you indicated: http://blog.stevex.net/index.php/c-c...5-hash-string/
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ga*******@gmail.com" wrote:
How do I go about implementing that in C#. I tried some of the various
x509 and pkcs7 classes and I kept getting exceptions having to do with
certificates and whatnot. I felt like I was wasting my time going down
the wrong path and this stuff doesn't seem too well documented on
msdn.microsoft.com.
>
Regards
>
Ben Voigt wrote:
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
>
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
>
const BYTE* sval[1];
unsigned long lval[1];
>
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
>
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
>
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
>
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
>
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
>
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
>
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
>
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
>
/**************************************/
>
And here is the C# code that I'm using:
>
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
>
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
>
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
>
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
>
Thanks in advance for any help I can get
>
>
>
Yeah, I've got the MD5 part . . . it's the "encoding of a PKCS #7 X.509
message" part that I'm not sure how to implement.
Peter wrote:
Well, your original post said you were looking for an MD5 Hash. So, I guess
you are on your own.
Best of luck!
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ga*******@gmail.com" wrote:
I've looked at that post and it's basically doing exactly what I'm
doing, The only difference is tthat the author treats the incoming
string as unicode (which mine is not. It's ascii) and he converts to
HEX (which I can't do.. I have to convert to base64 since that's how
it's stored in the database). I did try this approach and, although I
got a different hash returned, it contained the same amount number of
charectars.
I don't see any reference here to ASN.1 encoding of a PKCS #7 X.509
message. How do I go about doing this in C#?
Regards,
Gregg
Peter wrote:
Here is somebody's blog post that should point you in the right direction.
It's not as complicated as you indicated:
> http://blog.stevex.net/index.php/c-c...5-hash-string/
>
Peter
>
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
>
>
>
>
"ga*******@gmail.com" wrote:
>
How do I go about implementing that in C#. I tried some of the various
x509 and pkcs7 classes and I kept getting exceptions having to do with
certificates and whatnot. I felt like I was wasting my time going down
the wrong path and this stuff doesn't seem too well documented on
msdn.microsoft.com.
Regards
Ben Voigt wrote:
<ga*******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
I am re-writing a C++ application in C# that takes a user's password,
encrypts it using MD5 (I think), and compares it to what was encrypted
and stored in the database when the user initially created their
password. The problem is that the C++ encryption generates 110
characters and the C# encryption generates only 24. The interesting
thing is that the 24 charectars generated by the C# MD5 algorithm
matches the last 24 charecters of the C++ encryption algorithm. Here is
the C++ code:
>
The C++ code is requesting ASN.1 encoding of a PKCS #7 X.509 message, which
will naturally add a humonguous header to the data.
>
/**************************************/
std::string PasswordHash::get_passwordhash(char *s)
{
std::string hashed_value;
const BYTE* sval[1];
unsigned long lval[1];
sval[0] = reinterpret_cast<BYTE*>(s);
lval[0] = lstrlen(s);
CRYPT_ALGORITHM_IDENTIFIER AlgId;
AlgId.pszObjId=szOID_RSA_MD5;
AlgId.Parameters.cbData=0;
CRYPT_HASH_MESSAGE_PARA hash;
hash.cbSize = sizeof(CRYPT_HASH_MESSAGE_PARA);
hash.dwMsgEncodingType = (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING);
hash.hCryptProv = NULL;
hash.HashAlgorithm = AlgId;
hash.pvHashAuxInfo = NULL;
unsigned long hash_length = 0;
if(!CryptHashMessage( &hash, FALSE, 1, sval, lval, NULL,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
BYTE* hash_data = new BYTE[hash_length + 1];
ZeroMemory(hash_data, hash_length + 1);
if(!CryptHashMessage(&hash, FALSE, 1, sval, lval, hash_data,
&hash_length, NULL, NULL))
{
DWORD error = GetLastError();
return hashed_value;
}
std::vector<char vhash_data;
vhash_data.resize(hash_length);
memcpy(&vhash_data[0], (void*)hash_data, hash_length);
base64<charencoder;
int state = 0;
encoder.put(vhash_data.begin(), vhash_data.end(),
std::back_inserter(hashed_value), state, base64<>::noline());
return hashed_value;
}
/**************************************/
And here is the C# code that I'm using:
string generatePassword(string password)
{
MD5 md5Hasher = new MD5CryptoServiceProvider();
byte[] data =
md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(pass word));
string s = Convert.ToBase64String(data);
return s;
}
C++ OUTPUT
--------------------------
"MEcGCSqGSIb3DQEHBaA6MDgCAQAwDAYIKoZIhvcNAgUFADATB gkqhkiG9w0BBwGgBgQEODg3OAQQAETe7sQ97Rm5UhJQeesXgQ= ="
C# OUTPUT
--------------------------
"AETe7sQ97Rm5UhJQeesXgQ=="
Am I doing something wrong in the C# code? Perhaps I'm not fully
understanding what the C++ code is doing.
Thanks in advance for any help I can get This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John |
last post by:
Is there an equivalent of COM on Linux that I can get through Python.
My need is to have some sort of language independent component
framework. I can think of CORBA but I have to have a server...
|
by: Michael Foord |
last post by:
Please pardon my ignorance on this one - but I'm not certain how the
sign bt is treated in python bitwise operators. I've trying to convert
a javascript DES encryption routine into python.
...
|
by: Robert Dodier |
last post by:
Hello,
Here's a thought that I'm sure has already occurred to
someone else, I just can't find any record of it yet.
An XML document is just a more verbose and clumsy representation
of an...
|
by: Vannela |
last post by:
Is there any equivalent control in .NET for the Power
builder DataWindow control?
I am explaining the Datawindow architecture to some extent.
Power Builder DataWindow Control has got different...
|
by: Frank Rachel |
last post by:
So I can focus on the correct areas of research, I was wondering if someone
could give me the .NET equivelents for this J2EE architecture:
JSP's make calls to local JavaBean Controls. The...
|
by: Marty |
last post by:
Hi,
What is the VB.NET equivalent of the VB6 ADODB.Connector and
ADODB.Recordset?
Thanks
Marty
|
by: Tim Conner |
last post by:
Hi,
I am an ex-delphi programmer, and I having a real hard time with the
following simple code (example ):
Which is the equivalent to the following code ?
var
chars : PChar;
sBack, s :...
|
by: karch |
last post by:
How would this C# contruct be represented in C++/CLI? Or is it even
possible?
PolicyLevel level = (enumerator->Current) as PolicyLevel;
Thanks,
Karch
|
by: Alan Silver |
last post by:
Hello,
I'm converting some old VB6 code to use with ASP.NET and have come
unstuck with the Asc() function. This was used in the old VB6 code to
convert a character to its ASCII numeric...
|
by: grid |
last post by:
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |