public override bool VerifyPassword(string password) { var secretKey = HashPassword(password, PasswordSaltValue, PasswordHashAlgorithm, PasswordSpinCount); var inputBlockKey = CryptoHelpers.HashBytes( CryptoHelpers.Combine(secretKey, new byte[] { 0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79 }), PasswordHashAlgorithm); Array.Resize(ref inputBlockKey, PasswordKeyBits / 8); var valueBlockKey = CryptoHelpers.HashBytes( CryptoHelpers.Combine(secretKey, new byte[] { 0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e }), PasswordHashAlgorithm); Array.Resize(ref valueBlockKey, PasswordKeyBits / 8); using (var cipher = CryptoHelpers.CreateCipher(PasswordCipherAlgorithm, PasswordKeyBits, PasswordBlockSize * 8, PasswordCipherChaining)) { var decryptedVerifier = CryptoHelpers.DecryptBytes(cipher, PasswordEncryptedVerifierHashInput, inputBlockKey, PasswordSaltValue); var decryptedVerifierHash = CryptoHelpers.DecryptBytes(cipher, PasswordEncryptedVerifierHashValue, valueBlockKey, PasswordSaltValue); var verifierHash = CryptoHelpers.HashBytes(decryptedVerifier, PasswordHashAlgorithm); for (var i = 0; i < Math.Min(decryptedVerifierHash.Length, verifierHash.Length); ++i) { if (decryptedVerifierHash[i] != verifierHash[i]) { return(false); } } return(true); } }
public override bool VerifyPassword(string password) { // 2.3.4.9 Password Verification (Standard Encryption) // 2.3.5.6 Password Verification var secretKey = GenerateSecretKey(password); var blockKey = ((Flags & EncryptionHeaderFlags.AES) != 0) ? secretKey : GenerateBlockKey(0, secretKey); using (var cipher = CryptoHelpers.CreateCipher(CipherAlgorithm, KeySize, BlockSize, CipherMode.ECB)) { using (var transform = cipher.CreateDecryptor(blockKey, SaltValue)) { var decryptedVerifier = CryptoHelpers.DecryptBytes(transform, Verifier); var decryptedVerifierHash = CryptoHelpers.DecryptBytes(transform, VerifierHash); var verifierHash = CryptoHelpers.HashBytes(decryptedVerifier, HashAlgorithm); for (var i = 0; i < 16; ++i) { if (decryptedVerifierHash[i] != verifierHash[i]) { return(false); } } return(true); } } }
public override byte[] GenerateSecretKey(string password) { using (var cipher = CryptoHelpers.CreateCipher(PasswordCipherAlgorithm, PasswordKeyBits, PasswordBlockSize * 8, PasswordCipherChaining)) { return(GenerateSecretKey(password, PasswordSaltValue, PasswordHashAlgorithm, PasswordEncryptedKeyValue, PasswordSpinCount, PasswordKeyBits, cipher)); } }
public override bool VerifyPassword(string password) { // 2.3.6.4 Password Verification var secretKey = GenerateSecretKey(password); var blockKey = GenerateBlockKey(0, secretKey); using (var cipher = CryptoHelpers.CreateCipher(CipherIdentifier.RC4, 0, 0, 0)) { using (var transform = cipher.CreateDecryptor(blockKey, null)) { var decryptedVerifier = CryptoHelpers.DecryptBytes(transform, EncryptedVerifier); var decryptedVerifierHash = CryptoHelpers.DecryptBytes(transform, EncryptedVerifierHash); var verifierHash = CryptoHelpers.HashBytes(decryptedVerifier, HashIdentifier.MD5); for (var i = 0; i < 16; ++i) { if (decryptedVerifierHash[i] != verifierHash[i]) { return(false); } } return(true); } } }
public StandardEncryptedPackageStream(Stream underlyingStream, byte[] secretKey, StandardEncryption encryption) { Cipher = CryptoHelpers.CreateCipher(encryption.CipherAlgorithm, encryption.KeySize, encryption.BlockSize, CipherMode.ECB); Decryptor = Cipher.CreateDecryptor(secretKey, encryption.SaltValue); var header = new byte[8]; underlyingStream.Read(header, 0, 8); DecryptedLength = BitConverter.ToInt32(header, 0); // Wrap CryptoStream to override the length and dispose the cipher and transform // Zip readers scan backwards from the end for the central zip directory, and could fail if its too far away // CryptoStream is forward-only, so assume the zip readers read everything to memory BaseStream = new CryptoStream(underlyingStream, Decryptor, CryptoStreamMode.Read); }
public override SymmetricAlgorithm CreateCipher() { return(CryptoHelpers.CreateCipher(CipherAlgorithm, KeyBits, BlockSize * 8, CipherChaining)); }
public override SymmetricAlgorithm CreateCipher() { return(CryptoHelpers.CreateCipher(CipherAlgorithm, KeySize, BlockSize, CipherMode.ECB)); }
public override SymmetricAlgorithm CreateCipher() { return(CryptoHelpers.CreateCipher(CipherIdentifier.RC4, 0, 0, 0)); }