コード例 #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
ファイル: Blowfish.cs プロジェクト: horato/IntWarsSharp
 public static extern void Decrypt1(BlowFish* handle, byte* buf, IntPtr n, int iMode = (int)BlowfishMode.ECB);