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); }
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); }
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); }
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); }
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)); }