MD5CryptoServiceProvider (ported from CryptHashData)

Discussion in 'ASP .Net Security' started by Tino, Feb 10, 2009.

  1. Tino

    Tino Guest

    Hello all,

    I am having some problems converting an old Borland C++ program into C# with
    ..Net. In the old software, we used a salt value to calculate the hash. We did
    like this:

    CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
    CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);

    // add salt to the hash (the salt is in phData)
    CryptHashData(hHash, pbData, SaltLength, 0);

    // hash source string
    CryptHashData(hHash, pSourceString.c_str(), pSourceString.Length(), 0);

    // retrieve hashed value
    CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)

    .... it worked like a dream. Now I did:

    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    HashAlgorithm md5 = new MD5CryptoServiceProvider();
    byte[] result = md5.ComputeHash(encoding.GetBytes(tbSource.Text));

    .... works even better - and gives me the same hash value as long as I am not
    using any salt. Now my question is, how do I get the salt value into the hash
    with the new .NET - method?

    I tried combining the salt with the source string before hashing it but that
    gives a different value. How would I do it to get the same result as in the
    old method when using a salt?

    Thanks in advance and best regards!

    Tino
    Tino, Feb 10, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ron proveniers

    anybody ported Jrunner to NIOS

    ron proveniers, Aug 18, 2004, in forum: VHDL
    Replies:
    0
    Views:
    681
    ron proveniers
    Aug 18, 2004
  2. Mike
    Replies:
    1
    Views:
    191
    S├ębastien Pouliot
    Oct 16, 2003
  3. Viktor Popov

    MD5CryptoServiceProvider class

    Viktor Popov, Sep 24, 2004, in forum: ASP .Net Security
    Replies:
    2
    Views:
    184
    Gabe Garza
    Sep 24, 2004
  4. Tino
    Replies:
    1
    Views:
    1,073
  5. Derrick
    Replies:
    0
    Views:
    198
    Derrick
    Aug 23, 2004
Loading...

Share This Page