protected override byte[] EncodeBytes(byte[] data, SecureString password) { var key = HashPassword(password, KEY_SIZE); var iv = GenerateSalt(IV_SIZE); var fish = new BlowFish(key) {IV = iv}; return Concat(iv, fish.Encrypt_CBC(data)); }
public void RoundTripTest() { Console.WriteLine("Start"); BlowFish b = new BlowFish("04B915BA43FEB5B6"); string org_text = "The quick brown fox jumped over the lazy dog."; //Console.WriteLine(plainText); string cipherText = b.Encrypt_CBC(org_text); //Console.WriteLine(cipherText); string decoded_text = b.Decrypt_CBC(cipherText); //Console.WriteLine(plainText); Assert.AreEqual(org_text, decoded_text); }
public void CorruptDecodeTest() { Console.WriteLine("Start"); BlowFish b = new BlowFish("04B915BA43FEB5B6"); string org_text = "The quick brown fox jumped over the lazy dog."; string cipherText = b.Encrypt_CBC(org_text); System.Text.StringBuilder corrupted_text = new System.Text.StringBuilder(cipherText); corrupted_text[3] = 'A'; corrupted_text[10] = 'B'; corrupted_text[50] = 'C'; string decoded_text = b.Decrypt_CBC(corrupted_text.ToString()); //Console.WriteLine(decoded_text); Assert.AreNotEqual(org_text, decoded_text); Console.WriteLine(System.Environment.GetEnvironmentVariable("Path")); }