public void DeDES(byte[] input, string opath, string key, int mode)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();

            des.Key = Crc64.Compute(ASCIIEncoding.ASCII.GetBytes(key));
            des.IV  = des.Key;
            if (mode == 48)
            {
                des.Mode = CipherMode.ECB;
            }
            else if (mode == 49)
            {
                des.Mode = CipherMode.CBC;
            }
            else
            if (mode == 50)
            {
                des.Mode = CipherMode.CFB;
            }

            MemoryStream     fsread     = new MemoryStream(input);
            ICryptoTransform DesDecrypt = des.CreateDecryptor();
            CryptoStream     Crypto     = new CryptoStream(fsread, DesDecrypt, CryptoStreamMode.Read);

            string decryptedString = new StreamReader(Crypto, Encoding.GetEncoding(1252)).ReadToEnd();
            string trimOutput      = decryptedString.Remove(0, 20);

            byte[] outputBytes = Encoding.GetEncoding(1252).GetBytes(trimOutput);
            File.WriteAllBytes(opath, outputBytes);
        }
        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);
        }
예제 #3
0
        public void EnDES()
        {
            //Prepare File
            FileStream fsEncrypted = new FileStream(opath, FileMode.Create, FileAccess.Write);
            //Create Cryptor
            DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

            switch (mode)
            {
            case 0:
                DES.Mode = CipherMode.ECB;
                break;

            case 1:
                DES.Mode = CipherMode.CBC;
                break;

            case 2:
                DES.Mode = CipherMode.CFB;
                break;
            }

            DES.Key = Crc64.Compute(ASCIIEncoding.ASCII.GetBytes(key));
            DES.IV  = DES.Key;

            SHA1 sha1 = SHA1.Create();

            ICryptoTransform DesEncrypt = DES.CreateEncryptor();
            CryptoStream     Crypto     = new CryptoStream(fsEncrypted, DesEncrypt, CryptoStreamMode.Write);

            byte[] ByteArrayinput = File.ReadAllBytes(fpath);
            byte[] Hashdata       = sha1.ComputeHash(ByteArrayinput);

            byte[] Final = new byte[Hashdata.Length + ByteArrayinput.Length];

            System.Buffer.BlockCopy(Hashdata, 0, Final, 0, Hashdata.Length);
            System.Buffer.BlockCopy(ByteArrayinput, 0, Final, Hashdata.Length, ByteArrayinput.Length);
            //string mergeString = Encoding.GetEncoding(1252).GetString(Final);
            Crypto.Write(Final, 0, Final.Length);
            Crypto.Close();

            fsEncrypted.Close();

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

            sw.Write("D");
            sw.Write(this.mode);
            sw.Close();
        }
예제 #4
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();
        }