Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default MD5 implementation

    I need to use MD5 to generate a hash of a string. It needs to be
    compatible with the MD5 implementation in PHP.

    public string ComputeMD5(string plain)
    {
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] bMD5Hash = Encoding.ASCII.GetBytes(plain);
    return Encoding.ASCII.GetString(md5.ComputeHash(bMD5Hash) );
    //return Convert.ToBase64String(md5.ComputeHash(bMD5Hash));
    }


    With PHP I get:
    md5('test1test1test1test1test1test1') = '0b2fc97f2a37500552d805c4727295a8'

    In .NET I get:
    ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
    ComputeMD5('test1test1test1test1test1test1') = 'Cy/Jfyo3UAVS2AXEcnKVqA=='
    (base64)

    Am I doing it wrong or are the PHP and .NET implementations not compatible?

    Thanks in advance,
    Casper Hornstrup



    Casper Hornstrup Guest

  2. Similar Questions and Discussions

    1. web cam implementation
      Hello: Does anyone know of a way to implement a web cam with 30 second interval picture updates? This would be placed in a studio setting (radio)...
    2. RSA implementation for PHP
      Hi @ll, Is there a RSA library for php available? Has somebody any samples to decrypt a encrypted message with the public key given in a...
    3. RSA implementation of PHP
      Hi @ll, Is there a RSA library for php available? Has somebody any samples to decrypt a encrypted message with the public key given in a...
    4. NAT implementation on AIX 5.x
      Hi: I have a need to write my own version of NAT for AIX 5.x. I have been able to do this on HP-UX by using a STREAMS module and DLPI approach....
    5. PB & Implementation Files & C++
      Hi, I'm trying out PB for a C++ class at school. The program in question needs a main file and implementation file (.cpp) and a header file (.h)....
  3. #2

    Default Re: MD5 implementation

    Hi,

    If you compare both hashes in the same encoding (the PHP version is in
    Hexadecimal and the .NET version is in base64 or binary.), they will match.

    --
    Hernan de Lahitte
    Lagash Systems S.A.
    [url]http://www.lagash.com[/url]



    "Casper Hornstrup" <msdn@csite.com> wrote in message
    news:OZ$uuYw6DHA.1804@TK2MSFTNGP12.phx.gbl...
    > I need to use MD5 to generate a hash of a string. It needs to be
    > compatible with the MD5 implementation in PHP.
    >
    > public string ComputeMD5(string plain)
    > {
    > MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    > byte[] bMD5Hash = Encoding.ASCII.GetBytes(plain);
    > return Encoding.ASCII.GetString(md5.ComputeHash(bMD5Hash) );
    > //return Convert.ToBase64String(md5.ComputeHash(bMD5Hash));
    > }
    >
    >
    > With PHP I get:
    > md5('test1test1test1test1test1test1') = '0b2fc97f2a37500552d805c4727295a8'
    >
    > In .NET I get:
    > ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
    > ComputeMD5('test1test1test1test1test1test1') = 'Cy/Jfyo3UAVS2AXEcnKVqA=='
    > (base64)
    >
    > Am I doing it wrong or are the PHP and .NET implementations not
    compatible?
    >
    > Thanks in advance,
    > Casper Hornstrup
    >
    >
    >

    Hernan de Lahitte Guest

  4. #3

    Default Re: MD5 implementation

    Thanks for you answer.
    How do I get a string in the .NET version that I can compare to the PHP
    generated string and have a match?

    Casper

    "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    news:uLq9jnx6DHA.2404@TK2MSFTNGP12.phx.gbl...
    > Hi,
    >
    > If you compare both hashes in the same encoding (the PHP version is in
    > Hexadecimal and the .NET version is in base64 or binary.), they will
    match.
    >
    > --
    > Hernan de Lahitte
    > Lagash Systems S.A.
    > [url]http://www.lagash.com[/url]
    >
    >
    >
    > "Casper Hornstrup" <msdn@csite.com> wrote in message
    > news:OZ$uuYw6DHA.1804@TK2MSFTNGP12.phx.gbl...
    > > I need to use MD5 to generate a hash of a string. It needs to be
    > > compatible with the MD5 implementation in PHP.
    > >
    > > public string ComputeMD5(string plain)
    > > {
    > > MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    > > byte[] bMD5Hash = Encoding.ASCII.GetBytes(plain);
    > > return Encoding.ASCII.GetString(md5.ComputeHash(bMD5Hash) );
    > > //return Convert.ToBase64String(md5.ComputeHash(bMD5Hash));
    > > }
    > >
    > >
    > > With PHP I get:
    > > md5('test1test1test1test1test1test1') =
    '0b2fc97f2a37500552d805c4727295a8'
    > >
    > > In .NET I get:
    > > ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
    > > ComputeMD5('test1test1test1test1test1test1') =
    'Cy/Jfyo3UAVS2AXEcnKVqA=='
    > > (base64)
    > >
    > > Am I doing it wrong or are the PHP and .NET implementations not
    > compatible?
    > >
    > > Thanks in advance,
    > > Casper Hornstrup
    > >
    > >
    > >
    >
    >

    Casper Hornstrup Guest

  5. #4

    Default Re: MD5 implementation

    This code will encode in Hexa your hashed byte array.

    public static string EncodeHexString(byte[] sArray)
    {
    StringBuilder sb = new StringBuilder( sArray.Length * 2 );
    for(int index = 0; index < sArray.Length; index++)
    {
    sb.AppendFormat( "{0:X2}", sArray[index] );
    }
    return sb.ToString();
    }

    --
    Hernan de Lahitte
    Lagash Systems S.A.
    [url]http://www.lagash.com[/url]



    "Casper Hornstrup" <msdn@csite.com> wrote in message
    news:#Id1qyx6DHA.2044@TK2MSFTNGP10.phx.gbl...
    > Thanks for you answer.
    > How do I get a string in the .NET version that I can compare to the PHP
    > generated string and have a match?
    >
    > Casper
    >
    > "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    > news:uLq9jnx6DHA.2404@TK2MSFTNGP12.phx.gbl...
    > > Hi,
    > >
    > > If you compare both hashes in the same encoding (the PHP version is in
    > > Hexadecimal and the .NET version is in base64 or binary.), they will
    > match.
    > >
    > > --
    > > Hernan de Lahitte
    > > Lagash Systems S.A.
    > > [url]http://www.lagash.com[/url]
    > >
    > >
    > >
    > > "Casper Hornstrup" <msdn@csite.com> wrote in message
    > > news:OZ$uuYw6DHA.1804@TK2MSFTNGP12.phx.gbl...
    > > > I need to use MD5 to generate a hash of a string. It needs to be
    > > > compatible with the MD5 implementation in PHP.
    > > >
    > > > public string ComputeMD5(string plain)
    > > > {
    > > > MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    > > > byte[] bMD5Hash = Encoding.ASCII.GetBytes(plain);
    > > > return Encoding.ASCII.GetString(md5.ComputeHash(bMD5Hash) );
    > > > //return Convert.ToBase64String(md5.ComputeHash(bMD5Hash));
    > > > }
    > > >
    > > >
    > > > With PHP I get:
    > > > md5('test1test1test1test1test1test1') =
    > '0b2fc97f2a37500552d805c4727295a8'
    > > >
    > > > In .NET I get:
    > > > ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
    > > > ComputeMD5('test1test1test1test1test1test1') =
    > 'Cy/Jfyo3UAVS2AXEcnKVqA=='
    > > > (base64)
    > > >
    > > > Am I doing it wrong or are the PHP and .NET implementations not
    > > compatible?
    > > >
    > > > Thanks in advance,
    > > > Casper Hornstrup
    > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Hernan de Lahitte Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139