The Hash Class
I’ve been working on a C# Library to make hashing strings an easy (and fun?) task. I’ll show you the very basic bare-bones usage here:
Hashing mudkipz = new Hashing();
string m5 = mudkipz.md5("So, I herd u liek mudkipz.");
string s1 = mudkipz.sha1("So, I herd u liek mudkipz.");
string s256 = mudkipz.sha256("So, I herd u liek mudkipz.");
string s384 = mudkipz.sha384("So, I herd u liek mudkipz.");
string s512 = mudkipz.sha512("So, I herd u liek mudkipz.");
The library currently supports md5, sha1, sha256, sha384, and sha512. So yeah that’s all nice and easy to use and such but it there more? Yes, there is! There are four different formats your string can be hashed into:
- AB-CD-EF (default)
- ab-cd-ef
- ABCDEF
- abcdef
For any of you that have used PHP’s hashing functions you’ll notice that format number 4 is identical. Let’s say you want to have everything be formatted like PHP does. Using format 4.
Hashing mudkipz = new Hashing();
mudkipz.setFormat(4);
string blah1 = mudkipz.md5("So, I herd u liek mudkipz.");
string blah2 = mudkipz.sha1("So, I herd u liek mudkipz.");
You’ll notice that both strings will be formatted in the same way PHP would. We can switch back in the middle too.
Hashing mudkipz = new Hashing();
mudkipz.setFormat(4);
string blah1 = mudkipz.md5("So, I herd u liek mudkipz.");
string blah2 = mudkipz.sha1("So, I herd u liek mudkipz.");
mudkipz.setFormat(1);
string blah3 = mudkipz.md5("So, I herd u liek mudkipz.");
string blah4 = mudkipz.sha1("So, I herd u liek mudkipz.");
What if you want everything to be formatted with format 3 except for just one? Ya know, the odd man out. Instead of switching default formats you can just specify a extra format parameter.
Hashing mudkipz = new Hashing();
mudkipz.setFormat(3);
string blah1 = mudkipz.md5("So, I herd u liek mudkipz.");
string blah2 = mudkipz.sha1("So, I herd u liek mudkipz.", 4);
string blah3 = mudkipz.sha256("So, I herd u liek mudkipz.");
blah2 would then be formatted using format 4. All the others would use format 3.
That’s just about it. It’s licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. A link back would be nice, but not necessary.
Use the following links to download. Enjoy!
Hashing DLL (27)
