Ejemplo n.º 1
0
        public Database(string magicWord, string password)
        {
            RootFolderModels = new List <FolderModel>();
            var random = RandomNumberGenerator.Create();

            _initializationVector = new byte[16];
            random.GetBytes(_initializationVector);
            byte[] salt = CreateSalt(32);
            _magicWordByte = GenerateSaltedHash(ConvertToByte(magicWord), salt);
            byte[]       passwordByte = ConvertToByte32Array(password);
            EncryptorAES AES          = new EncryptorAES();

            _encodedMagicWordByte = AES.EncryptStringToBytes(ConvertByteToString(_magicWordByte), passwordByte, _initializationVector);
        }
Ejemplo n.º 2
0
 internal void CheckPassword(string password)
 {
     try
     {
         byte[]       passwordByte         = ConvertToByte32Array(password);
         EncryptorAES AES                  = new EncryptorAES();
         string       decodedMagicWord     = AES.DecryptStringFromBytes(_encodedMagicWordByte, passwordByte, _initializationVector);
         byte[]       decodedMagicWordByte = ConvertToByte(decodedMagicWord);
         if (Enumerable.SequenceEqual(decodedMagicWordByte, _magicWordByte))
         {
             _key = passwordByte;
         }
         //else
         //{
         //    throw new Exception("Wrong password!");
         //}
     }
     catch
     {
         throw new UnauthorizedAccessException("Wrong password!");
     }
 }