Friday, March 4, 2011

Quick and Dirty Sha1 Hash Creation

I had the need to hash a password to get a Sha1 Hash. I've got ruby on my system so I thought I should be able to do that with Ruby. Quick search, found this and did this snippet...
require 'digest/sha1'
sha1 = Digest::SHA1.hexdigest('passwordHerePlease')
Easier than opening Visual Studio, creating a project, inserting this in some function, importing the namespace System.Security.Cryptography, compiling, and running... :)
SHA1CryptoServiceProvider cryptoTransformSHA1 = 
    new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
    cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

P.S. I was wondering how to turn the bytes into a Sha1 like what Ruby outputs. The code above for C# was from here

No comments:

Post a Comment