private static string Encrypt(string s)
{
HashAlgorithm provider = null;
try {
provider = new SHA1Managed();
byte[] bytes = Encoding.Unicode.GetBytes(s);
provider.Initialize();
bytes = provider.ComputeHash(bytes);
return Convert.ToBase64String(bytes);
}
finally {
if (provider != null)
provider.Clear();
}
}
####
use strict;
use MIME::Base64;
use Digest::SHA1 qw/sha1 sha1_hex sha1_base64/;
use Encode qw/encode decode/;
print 'Hello World' . "\n";
print encode_base64(sha1('1234')) . "\n";
print decode("UCS-2BE", decode_base64('E59pyTwEJJao6VjsWTBmLGzMr78='));
####
// s = '1234'
private static string Encrypt(string s)
{
HashAlgorithm provider = null;
try {
provider = new SHA1Managed();
byte[] bytes = Encoding.Unicode.GetBytes(s);
// bytes = 49, 0, 50, 0, 51, 0, 52, 0
provider.Initialize();
bytes = provider.ComputeHash(bytes);
// bytes = 19, 519, 105, 201, 60, 4, 36, 150, 168, 233, 88, 236, 89, 48, 102, 44, 108, 204, 175, 191
return Convert.ToBase64String(bytes);
// bytes = E59pyTwEJJao6VjsWTBmLGzMr78=
}
finally {
if (provider != null)
provider.Clear();
}
}