To Examples
Hash Example, source code file Program.cs
using System; using System.Text; using System.IO; using System.Security.Cryptography; // Login Example -- GeneratePasswordFile // Generate username and encrypted // passwords for password file. namespace LoginFileGenerator { public class Program { public static void Main() { // Array of usernames and unencrypted passwords. string[] unEncryptedEntries = {"dduck,whatsupdoc9", "efudd,abcxyz*", "ppig,porky192837465!", "sjost,rainbow9"}; // Set encryption key. string strKey = "upwk1133557799#"; byte[] key = Encoding.ASCII.GetBytes(strKey.ToCharArray( )); // Create hash object. HMACSHA1 hmac = new HMACSHA1(key); // Compute password file entries and write them to password file. StreamWriter w = new StreamWriter("../../passwords.txt"); foreach(string entry in unEncryptedEntries) { string[] fields = entry.Split(','); byte[] pw = Encoding.ASCII.GetBytes(fields[1].ToCharArray()); byte[] hash = hmac.ComputeHash(pw); string pwFileEntry = fields[0] + ";" + Convert.ToBase64String(hash); w.WriteLine(pwFileEntry); } // Close password file. w.Close(); } } }