Ask a Question related to ASP.NET Security, Design and Development.
-
Casper Hornstrup #1
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
-
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)... -
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... -
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... -
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.... -
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).... -
Hernan de Lahitte #2
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...compatible?> 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>
> Thanks in advance,
> Casper Hornstrup
>
>
>
Hernan de Lahitte Guest
-
Casper Hornstrup #3
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...match.> 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'0b2fc97f2a37500552d805c4727295a8'>
> --
> 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') ='Cy/Jfyo3UAVS2AXEcnKVqA=='> >
> > In .NET I get:
> > ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
> > ComputeMD5('test1test1test1test1test1test1') => compatible?> > (base64)
> >
> > Am I doing it wrong or are the PHP and .NET implementations not>> >
> > Thanks in advance,
> > Casper Hornstrup
> >
> >
> >
>
Casper Hornstrup Guest
-
Hernan de Lahitte #4
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...> match.> > 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> '0b2fc97f2a37500552d805c4727295a8'> >
> > --
> > 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') => 'Cy/Jfyo3UAVS2AXEcnKVqA=='> > >
> > > In .NET I get:
> > > ComputeMD5('test1test1test1test1test1test1') = ' /I*7PRXDrr('
> > > ComputeMD5('test1test1test1test1test1test1') =>> > compatible?> > > (base64)
> > >
> > > Am I doing it wrong or are the PHP and .NET implementations not> >> > >
> > > Thanks in advance,
> > > Casper Hornstrup
> > >
> > >
> > >
> >
>
Hernan de Lahitte Guest



Reply With Quote

