Beispiel #1
0
        private static string decryptSeed(int userId)
        {
            byte[] seed       = retrieveSeed(userId);
            string seedBase32 = null;

            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.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(seed, 0, seed.Length);
                        cs.Close();
                    }
                    seed = msEncrypt.ToArray();
                }

                seedBase32 = Base32.ToBase32String(seed);
            }

            return(seedBase32);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public static string ToBase32String(byte[] data)
 {
     return(Base32.ToBase32String(data));
 }