Esempio n. 1
0
        // Generating 26 length string of random characters for the Secret Key
        public static byte[] GenerateSecretKey(string username)
        {
            Dictionary <double, char> numberToCharacter = Utils.numberToCharacter;
            StringBuilder             secretKey         = new StringBuilder();

            for (int i = 0; i < SECRET_KEY_LENGTH; i++)
            {
                byte[] randomNumber = new byte[8];
                rngCsp.GetBytes(randomNumber);
                double generatedNumber = Math.Abs((BitConverter.ToInt32(randomNumber, 0) % 31));

                if (numberToCharacter.ContainsKey(generatedNumber))
                {
                    secretKey.Append(numberToCharacter[generatedNumber]);
                }
                else
                {
                    throw new Exception("Value not found in dictionary.");
                }
            }

            byte[] expandedSecretKey = MyHKDF.KeyExpansion(32, Encoding.ASCII.GetBytes(secretKey.ToString()), username);

            return(expandedSecretKey);
        }
Esempio n. 2
0
        private static byte[] DeriveMasterUnlockKey(byte[] masterPassword, string username)
        {
            byte[] salt           = DataStore.GetData(Globals.Salt);
            byte[] hashedPassword = PBKDF2.PerformPBKDF(masterPassword, salt);

            byte[] secretKey         = DataStore.GetData(Globals.SecretKey);
            byte[] expandedSecretKey = MyHKDF.KeyExpansion(32, secretKey);

            return(XOR(hashedPassword, expandedSecretKey));
        }
Esempio n. 3
0
 private static byte[] HandleSalt(byte[] salt)
 {
     if (salt.Length == OUTPUT_LENGTH_IN_BYTES)
     {
         return(salt);
     }
     else
     {
         return(MyHKDF.KeyExpansion(OUTPUT_LENGTH_IN_BYTES, salt));
     }
 }