示例#1
0
        private bool VerifyAuthentication(string email, string password)
        {
            BinaryReader binaryReader = this.GetBinaryReader();

            this.headerLength    = binaryReader.ReadInt64();
            this.encryptedEmail  = binaryReader.ReadBytesWithLength();
            this.hashedPassword  = binaryReader.ReadBytes(32);
            this.saltForPassword = binaryReader.ReadBytes(32);
            if (!this.hashedPassword.SequenceEqual(CipherFile.PBKDF2(password, this.saltForPassword, 1000, 32)))
            {
                return(false);
            }
            this.saltForDataA   = binaryReader.ReadBytes(32);
            this.saltForDataAIV = binaryReader.ReadBytes(16);
            this.CreateAesForDataA(password);
            if (email != this.aesForDataA.DecryptionToString(this.encryptedEmail, "Unicode"))
            {
                return(false);
            }
            this.authentication = true;
            this.saltForDataB   = binaryReader.ReadBytes(32);
            this.saltForDataBIV = binaryReader.ReadBytes(16);
            this.CreateCryptProviderWithoutAesForDataA(password);
            this.email = email;
            return(true);
        }
示例#2
0
 private void CreateCryptProvider(string password)
 {
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentNullException("password");
     }
     if (this.saltForDataA == null)
     {
         this.saltForDataA = this.csrng.Generate(256).Bytes;
     }
     if (this.saltForDataAIV == null)
     {
         this.saltForDataAIV = this.csrng.Generate(128).Bytes;
     }
     if (this.saltForDataB == null || this.saltForDataBIV == null)
     {
         this.saltForDataB = this.csrng.Generate(256).Bytes;
     }
     if (this.saltForDataBIV == null)
     {
         this.saltForDataBIV = this.csrng.Generate(128).Bytes;
     }
     byte[] array  = CipherFile.PBKDF2(password, this.saltForDataA, 1000, 32);
     byte[] iv     = CipherFile.PBKDF2(password, this.saltForDataAIV, 1000, 16);
     byte[] array2 = CipherFile.PBKDF2(password, this.saltForDataB, 1000, 32);
     byte[] iv2    = CipherFile.PBKDF2(password, this.saltForDataBIV, 1000, 16);
     byte[] key    = array.Concat(array2).ToArray <byte>();
     this.aesForDataA = this.CreateAesProvider(array, iv);
     this.aesForDataB = this.CreateAesProvider(array2, iv2);
     this.hmacsha256  = new HMACSHA256(key);
 }
示例#3
0
 private void ModifyPassword(string password)
 {
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentNullException("password");
     }
     this.saltForPassword = this.csrng.Generate(256).Bytes;
     this.hashedPassword  = CipherFile.PBKDF2(password, this.saltForPassword, 1000, 32);
     this.saltForDataA    = this.csrng.Generate(256).Bytes;
     this.saltForDataBIV  = this.csrng.Generate(128).Bytes;
     this.saltForDataB    = this.csrng.Generate(256).Bytes;
     this.saltForDataBIV  = this.csrng.Generate(128).Bytes;
     this.CreateCryptProvider(password);
 }
示例#4
0
 private void CreatePassword(string password)
 {
     if (this.hashedPassword != null)
     {
         throw new ApplicationException("Password已经存在,若要修改密码请使用ModifyPassword");
     }
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentNullException("password");
     }
     this.saltForPassword = this.csrng.Generate(256).Bytes;
     this.hashedPassword  = CipherFile.PBKDF2(password, this.saltForPassword, 1000, 32);
     this.CreateCryptProvider(password);
 }
示例#5
0
 private void LoadAllCipherFile()
 {
     string[] files = Directory.GetFiles(this.DataDirectory);
     string[] array = files;
     for (int i = 0; i < array.Length; i++)
     {
         string     fileName   = array[i];
         CipherFile cipherFile = new CipherFile(fileName);
         if (cipherFile.CheckIdentification())
         {
             this.CipherFileList.Add(cipherFile);
         }
     }
 }
示例#6
0
 private void CreateAesForDataA(string password)
 {
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentNullException("password");
     }
     if (this.saltForDataA == null)
     {
         this.saltForDataA = this.csrng.Generate(256).Bytes;
     }
     if (this.saltForDataAIV == null)
     {
         this.saltForDataAIV = this.csrng.Generate(128).Bytes;
     }
     this.aesForDataA = this.CreateAesProvider(CipherFile.PBKDF2(password, this.saltForDataA, 1000, 32), CipherFile.PBKDF2(password, this.saltForDataAIV, 1000, 16));
 }