static void Main(string[] args) { var KEY = "12345678901234567890".Select(m => (byte)m).ToArray(); Console.Error.WriteLine(Base32.ToBase32String(KEY)); //* do { Console.Clear(); Console.Error.WriteLine("TOTP Generated:\t{0}", DateTime.Now.ToLongTimeString()); var CurrentOffset = HOTP.GetCounter() - 5; for (var i = 0; i < 5; i++) { Console.Error.WriteLine("TOTP Counter:\t{0}", CurrentOffset + i); Console.Error.WriteLine("TOTP Token:\t{0:000000}", HOTP.GetHOTP(KEY, CurrentOffset + i)); } }while (Console.ReadKey(true).Key != ConsoleKey.Escape); //*/ Console.Error.WriteLine("#END"); Console.ReadKey(true); }
public static void encryptSeed(int userId) { string seed = "CMFC4FUMEN7QNNHK4OZD2UVUIF6NJKPB"; byte[] seedBytes = Base32.FromBase32String(seed); using (Aes AES = Aes.Create()) { AES.KeySize = 256; AES.BlockSize = 128; AES.Key = PrivateKey.privKey; AES.IV = PrivateKey.privIV; AES.Mode = CipherMode.CBC; using (var msEncrypt = new MemoryStream()) { using (var cs = new CryptoStream(msEncrypt, AES.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(seedBytes, 0, seedBytes.Length); cs.Close(); } seedBytes = msEncrypt.ToArray(); } } SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Insert Into UserSeed(seedText, userId) " + "Values(@seedText, @userId);"; cmd.Parameters.AddWithValue("@seedText", seedBytes); cmd.Parameters.AddWithValue("@userId", userId); cmd.Connection = Service.GetConnection(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
public static string ToBase32String(byte[] data) { return(Base32.ToBase32String(data)); }
private byte[] FromBase32String(string base32string) { return(Base32.FromBase32String(base32string)); }