bkiahg has asked for the wisdom of the Perl Monks concerning the following question:
I've tried hundreds of variations on the below code trying to get the same results: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(); } }
To say the least I'm a bit lost and would love a point in the right direction or a friendly bit of advice.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(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Rewriting a C# Encryption Function
by jethro (Monsignor) on Aug 22, 2008 at 21:05 UTC | |
by bkiahg (Pilgrim) on Aug 22, 2008 at 21:45 UTC | |
by gone2015 (Deacon) on Aug 22, 2008 at 23:35 UTC | |
by bkiahg (Pilgrim) on Aug 25, 2008 at 14:26 UTC | |
by bkiahg (Pilgrim) on Aug 22, 2008 at 21:20 UTC | |
by jethro (Monsignor) on Aug 22, 2008 at 21:55 UTC | |
by graff (Chancellor) on Aug 23, 2008 at 00:14 UTC |