예제 #1
0
        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));
        }
예제 #2
0
        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()));
        }
예제 #3
0
 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("-", "");
 }
예제 #4
0
 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();
 }
예제 #5
0
파일: Main.cs 프로젝트: spiridenok/HOP
 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);
 }
예제 #6
0
파일: Main.cs 프로젝트: spiridenok/HOP
 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"));
 }
예제 #7
0
 public static extern void Decrypt1(BlowFish* handle, byte* buf, IntPtr n, int iMode = (int)BlowfishMode.ECB);