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)); }
protected override byte[] DecodeBytes(byte[] data, SecureString password) { var key = HashPassword(password, KEY_SIZE); var iv = data.Take(IV_SIZE).ToArray(); var fish = new BlowFish(key) { IV = iv }; return TrimRightNull(fish.Decrypt_CBC(data.Skip(IV_SIZE).ToArray())); }
public SHA256_Blowfish(Stream source) { key = new byte[BlowFish_KEY_SIZE_DEFAULT]; System.Buffer.BlockCopy(generateKey(), 0, key, 0, BlowFish_KEY_SIZE_DEFAULT); this.Source = source; blowfish = new BlowFish(key); blowfish.IV = BlowFish_IV_DEFAULT; initializeOutput(); this.Output.Key = BitConverter.ToString(key).Replace("-", ""); }
public SHA256_Blowfish(byte[] keySrc, Stream source) { keySrc = generateKey(keySrc); int length = Math.Min(keySrc.Length, BlowFish_KEY_SIZE_DEFAULT); key = new byte[length]; keySrc.CopyTo(key, 0); this.Source = source; blowfish = new BlowFish(keySrc); blowfish.IV = BlowFish_IV_DEFAULT; initializeOutput(); }
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")); }
public static extern void Decrypt1(BlowFish* handle, byte* buf, IntPtr n, int iMode = (int)BlowfishMode.ECB);