Exemplo n.º 1
0
        public void ByteArrayCompareReturnsFalseIfArraysAreNotTheSame()
        {
            byte[] test1 = { 0x01, 0xE5, 0x92, 0xBC, 0xE6, 0xA4, 0xBE, 0xE6, 0xA3, 0x8D, 0xE7, 0x9B, 0x90, 0xED, 0xBF, 0xB1 };
            byte[] test2 = { 0x05, 0xE6, 0x72, 0xBC, 0xE6, 0xA4, 0xBE, 0xE6, 0xA3, 0x8D, 0xE7, 0x9B, 0x90, 0xED, 0xBF, 0xB1 };

            Assert.IsFalse(ByteHelpers.ByteArrayCompare(test1, test2));
        }
Exemplo n.º 2
0
        public void GetBytesReturnsFixedByteArray()
        {
            byte[] testArray     = { 72, 0, 101, 0, 108, 0, 108, 0, 111, 0 };
            byte[] returnedBytes = ByteHelpers.GetBytes("Hello");

            Assert.IsTrue(ByteHelpers.ByteArrayCompare(testArray, returnedBytes));
        }
Exemplo n.º 3
0
        private void CheckFileIntegrity(byte[] hash, byte[] encrypted)
        {
            var computedhash = SecureHash.ComputeHash(encrypted);

            if (!ByteHelpers.ByteArrayCompare(computedhash, hash))
            {
                throw new InvalidOperationException("The signature of the file does not match.");
            }
        }
Exemplo n.º 4
0
        private static byte[] CheckHmac(byte[] dataToDecrypt, byte[] salt, AesCryptoServiceProvider aes)
        {
            var hmac          = ByteHelpers.CreateSpecialByteArray(32);
            var encryptedData = ByteHelpers.CreateSpecialByteArray(dataToDecrypt.Length - 32);

            Buffer.BlockCopy(dataToDecrypt, 0, hmac, 0, 32);
            Buffer.BlockCopy(dataToDecrypt, 32, encryptedData, 0, dataToDecrypt.Length - 32);

            var newHmac = CreateHmac(salt, aes, encryptedData);

            if (!ByteHelpers.ByteArrayCompare(hmac, newHmac))
            {
                throw new CryptographicException("The authenticated message code doesn't match. \n\nThe message may have been corrupted or tampered with.");
            }

            return(encryptedData);
        }
        private static bool ConfirmationPassword(PasswordEntry passwordEntry)
        {
            using (var passwordEntry2 = new PasswordEntry())
            {
                passwordEntry2.LabelText = "Please confirm your session password(s).";

                if (passwordEntry2.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                bool password1Match = ByteHelpers.ByteArrayCompare(passwordEntry.Password.Password1, passwordEntry2.Password.Password1);
                bool password2Match = ByteHelpers.ByteArrayCompare(passwordEntry.Password.Password2, passwordEntry2.Password.Password2);

                if ((password1Match == false) || (password2Match == false))
                {
                    MessageBox.Show(Resources.TextShredderMainForm_ConfirmationPassword_The_passwords_do_not_match_, Resources.TextShredderMainForm_ConfirmationPassword_The_passwords_do_not_match_, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return(false);
                }

                return(true);
            }
        }
Exemplo n.º 6
0
        public void ByteArrayCompareThrowsArgumentNullExceptionIfSecondParameterIsNull()
        {
            var test = new byte[5];

            ByteHelpers.ByteArrayCompare(test, null);
        }
Exemplo n.º 7
0
 public void ByteArrayCompareThrowsArgumentNullExceptionIfFirstParameterIsNull()
 {
     ByteHelpers.ByteArrayCompare(null, null);
 }