public void DeBlow(byte[] input, string opath, string key, int mode)
        {
            SHA256   sha256   = SHA256.Create();
            BlowFish blowFish = new BlowFish(sha256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key)));

            blowFish.SetIV(Crc64.Compute(ASCIIEncoding.ASCII.GetBytes(key)));

            byte[] decrypted = { };
            string cfbDecrypted;

            if (mode == 48)
            {
                decrypted = blowFish.Decrypt_ECB(input);
            }
            else if (mode == 49)
            {
                decrypted = blowFish.Decrypt_CBC(input);
            }
            else
            if (mode == 50)
            {
                decrypted = blowFish.Decrypt_CBC(input);
            }

            string stringToWrite = Encoding.GetEncoding(1252).GetString(decrypted);
            string trimOutput    = stringToWrite.Remove(0, 20);
            int    pos           = trimOutput.IndexOf('\0');

            if (pos > 0)
            {
                trimOutput = trimOutput.Substring(0, pos);
            }
            byte[] outputBytes = Encoding.GetEncoding(1252).GetBytes(trimOutput);
            File.WriteAllBytes(opath, outputBytes);
        }
Exemplo n.º 2
0
        public void EnBlowFish()
        {
            //Read Input file
            byte[] arrayinput = File.ReadAllBytes(fpath);

            //Hash Plaintext
            SHA1 sha1 = SHA1.Create();

            byte[] Hashdata = sha1.ComputeHash(arrayinput);
            byte[] Final    = new byte[Hashdata.Length + arrayinput.Length];
            System.Buffer.BlockCopy(Hashdata, 0, Final, 0, Hashdata.Length);
            System.Buffer.BlockCopy(arrayinput, 0, Final, Hashdata.Length, arrayinput.Length);
            //Hash key
            SHA256 sha256 = SHA256.Create();
            //            aes.Key = sha256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(this.key));
            //          System.Buffer.BlockCopy(aes.Key, 0, aes.IV, 0, aes.Key.Length / 2);

            BlowFish b = new BlowFish(sha256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(this.key)));

            b.SetIV(Crc64.Compute(ASCIIEncoding.ASCII.GetBytes(this.key)));

            byte[] arrayenc;
            if (this.mode == 0)
            {
                arrayenc = b.Encrypt_ECB(Final);
            }
            else if (this.mode == 1)
            {
                arrayenc = b.Encrypt_CBC(Final);
            }
            else
            {
                arrayenc = b.Encrypt_CBC(Final);
            }

            FileStream fOutput = new FileStream(this.opath, FileMode.Create, FileAccess.Write);

            fOutput.Write(arrayenc, 0, arrayenc.Length);

            fOutput.Close();

            StreamWriter sw = File.AppendText(this.opath);

            sw.Write("B");
            sw.Write(this.mode);
            sw.Close();
        }