Hi,
I’m writing this in english ‘cause I think most of the people interested into
this are speaking english.
Well, to the point. I recently had the problem to compare sha1-values of a
string that were generated by php with those generated from c#.
They differed, even with the encoding set correctly (My guess would be: Blaim php. ^^). As always, there was no time
to sit and think about an elegant solution, so here is my solution made with
steamroller tactics...
First, create a simple php script, named "phpSHA1.php" in this example:
This has to be compiled to exe using bambalam:
> bamcompile.exe phpSHA1.exe
Now, let the fun begin. 
Write a new method wherever you want to use it:
using System.
Convert;
using System.
Diagnostics;
...
public string sha1
(string text
) { Encoding coder = Encoding.
GetEncoding(1252);
byte[] encbuff = coder.
GetBytes(text
);
string tr = Convert.
ToBase64String(encbuff
);
// Start the child process. Process p =
{FNAMEL}+msdn.microsoft.com">new Process
();
// Redirect the output stream of the child process. p.
StartInfo.
UseShellExecute =
false;
p.
StartInfo.
RedirectStandardOutput =
true;
p.
StartInfo.
RedirectStandardInput =
true;
p.
StartInfo.
CreateNoWindow =
true;
p.
StartInfo.
FileName = "phpSHA1.
exe";
p.
Start();
p.
StandardInput.
WriteLine(tr
);
// Read the output stream first and then wait. string output = p.
StandardOutput.
ReadToEnd();
p.
WaitForExit();
return output;
}
Finished, now php generates the sha1-hash for you, so no differences anymore.
There are no checks wether the .exe exists or not in this example (or any trying and catching at all), so add this yourself.
If anyone knows a solution without letting php do the work, feel free to comment.