Convert VB.net Function into C++ in linux

Hi

Im newbee in linux programming. n dunno how to convert this vb.net source code in windows to c++ in linux

this is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
Private Function MD5(ByVal StrText As String) As String
On Error Resume Next
Dim hProv As Long, phHash As Long, pdwDataLen As Long, pbData() As Byte
Call CryptAcquireContext(hProv, vbNullString, vbNullString, 1, &HF0000000)
Call CryptCreateHash(hProv, 32768 Or 0 Or 3, 0, 0, phHash)
Call CryptHashData(phHash, ByVal StrText, Len(StrText), 0)
Call CryptGetHashParam(phHash, 4, pdwDataLen, 4, 0)
ReDim pbData(0 To pdwDataLen - 1)
Call CryptGetHashParam(phHash, 2, pbData(0), pdwDataLen, 0)
MD5 = StrConv(pbData, vbUnicode)
CryptDestroyHash phHash
CryptReleaseContext hProv, 0
End Function


Please Help me.

Thanks in advance.

Regards,
Syerwin
OpenSSL has a nifty function called MD5(). Check the MD5(3) man page ("man 3 MD5" at the command-line).

I'm not sure what StrConv() does on line 10, so this may not be complete. I typically export the hash base64 encoded.

1
2
3
4
5
6
7
8
9
std::string md5(const std::string& text)
{
    char digest[MD5_DIGEST_LENGTH];
    MD5(
        reinterpret_cast<const unsigned char*>(text.c_str()),
        text.size(),
        reinterpret_cast<unsigned char*>(digest));
    return std::string(digest, digest + MD5_DIGEST_LENGTH);
}


You will need to link the code with "-lssl".

Topic archived. No new replies allowed.