public void TestEncryptWithPasswordWithSalt() { byte[] salt = CreateRandomData(128); byte[] data = CreateRandomData(1000); byte[] encryptedData; string base64EncryptedData; using (ICrypto crypto = new AesCrypto("password!", salt)) { encryptedData = crypto.Encrypt(data); base64EncryptedData = crypto.EncryptToBase64(data); } byte[] decryptedData; byte[] decryptedDataFromBase64; using (ICrypto crypto = new AesCrypto("password!", salt)) { decryptedData = crypto.Decrypt(encryptedData); decryptedDataFromBase64 = crypto.Decrypt(base64EncryptedData); } TestHelper.AreEqual(data, decryptedData); TestHelper.AreEqual(data, decryptedDataFromBase64); }
public void TestHashAndEncryptFromString() { string data = "Some test data"; byte[] encryptedData; string base64EncryptedData; using (ICrypto crypto = new AesCrypto("password!")) { encryptedData = crypto.HashAndEncrypt(data); base64EncryptedData = crypto.HashAndEncryptToBase64(data); } string decryptedData; string decryptedDataFromBase64; using (ICrypto crypto = new AesCrypto("password!")) { decryptedData = crypto.DecryptToStringAndCheckHash(encryptedData); decryptedDataFromBase64 = crypto.DecryptToStringAndCheckHash(base64EncryptedData); } Assert.AreEqual(data, decryptedData); Assert.AreEqual(data, decryptedDataFromBase64); }
public void TestEncryptWithSevenCharPassword() { byte[] data = CreateRandomData(1000); using (ICrypto crypto = new AesCrypto("1234567")) { crypto.Encrypt(data); } }
public void TestHashAndEncryptWithNoData() { byte[] data = new byte[0]; byte[] encryptedData; using (ICrypto crypto = new AesCrypto("password!")) { encryptedData = crypto.HashAndEncrypt(data); } byte[] decryptedData; using (ICrypto crypto = new AesCrypto("password!")) { decryptedData = crypto.DecryptAndCheckHash(encryptedData); } Assert.AreEqual(0, decryptedData.Length); }
public void TestHashAndEncryptTamperingWithData() { byte[] data = CreateRandomData(1000); byte[] encryptedData; using (ICrypto crypto = new AesCrypto("password!")) { encryptedData = crypto.HashAndEncrypt(data); } //Tamper encryptedData[20] = (byte)~(uint)encryptedData[20]; using (ICrypto crypto = new AesCrypto("password!")) { crypto.DecryptAndCheckHash(encryptedData); } }
public void TestHashAndEncrypt() { byte[] data = CreateRandomData(1000); byte[] encryptedData; string base64EncryptedData; using (ICrypto crypto = new AesCrypto("password!")) { encryptedData = crypto.HashAndEncrypt(data); base64EncryptedData = crypto.HashAndEncryptToBase64(data); } byte[] decryptedData; byte[] decryptedDataFromBase64; using (ICrypto crypto = new AesCrypto("password!")) { decryptedData = crypto.DecryptAndCheckHash(encryptedData); decryptedDataFromBase64 = crypto.DecryptAndCheckHash(base64EncryptedData); } TestHelper.AreEqual(data, decryptedData); TestHelper.AreEqual(data, decryptedDataFromBase64); }