Пример #1
0
        public override void Convert(BlowfishNET.BlowfishECB ECB, AlgorithmType newalgorithm)
        {
            ecb          = ECB;
            oldalgorithm = algorithm;
            algorithm    = newalgorithm;

            if (compressedmem == null)
            {
                LoadAndCompress();
            }

            if (oldalgorithm == algorithm || compressedsize < BlowfishNET.BlowfishECB.BLOCK_SIZE)
            {
                return;
            }

            int encryptlen = (int)compressedsize;

            if (encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE != 0)
            {
                encryptlen -= encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE;
            }

            byte [] tmp = (byte [])compressedmem.GetBuffer().Clone();

            if (algorithm == AlgorithmType.infilateandblowfish)
            {
                ecb.Encrypt(tmp, 0, compressedmem.GetBuffer(), 0, encryptlen);
            }
            else
            {
                ecb.Decrypt(tmp, 0, compressedmem.GetBuffer(), 0, encryptlen);
            }
            adler32 = AdlerCheckSum.GetAdler32(compressedmem, 0, (int)compressedmem.Length);
        }
Пример #2
0
        public static Kom2SubFileFromKom ReadSubFileFromKom(BlowfishNET.BlowfishECB CBC, string komfilename, System.Xml.XmlElement node, UInt32 offset)
        {
            Kom2SubFileFromKom subfile = new Kom2SubFileFromKom();

            subfile.ecb      = CBC;
            subfile.filename = komfilename;
            subfile.ReadHeader(node);
            subfile.offset = offset;
            return(subfile);
        }
Пример #3
0
        public void Close()
        {
            adler32     = 0;
            header_size = 0;
            filetime    = 0;

            foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles)
            {
                KeyValue.Value.Close();
            }

            subfiles.Clear();
            ecb     = null;
            komtype = EKomType.notkom;
        }
Пример #4
0
        public bool Decrypt()
        {
            if (ecb == null)
            {
                return(false);
            }

            foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles)
            {
                if ((Kom2SubFile.AlgorithmType)KeyValue.Value.Algorithm == Kom2SubFile.AlgorithmType.infilateandblowfish) // 인크립트 되있으면 풀자
                {
                    KeyValue.Value.Convert(ecb, Kom2SubFile.AlgorithmType.infilate);
                }
            }

            ecb     = null;
            komtype = EKomType.newkom;
            return(true);
        }
Пример #5
0
        public override void Convert(BlowfishNET.BlowfishECB ECB, AlgorithmType newalgorithm)
        {
            ecb       = ECB;
            algorithm = newalgorithm;

            if (oldalgorithm == algorithm || compressedsize < BlowfishNET.BlowfishECB.BLOCK_SIZE)
            {
                compressedmem = null;
                return;
            }

            int encryptlen = (int)compressedsize;

            compressedmem = new System.IO.MemoryStream();
            System.IO.FileStream filestream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            filestream.Position = offset;
            byte[] data = new byte[encryptlen];
            filestream.Read(data, 0, encryptlen);
            byte[] tmp = (byte[])data.Clone();

            if (encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE != 0)
            {
                encryptlen -= encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE;
            }

            if (algorithm == AlgorithmType.infilateandblowfish)
            {
                ecb.Encrypt(tmp, 0, data, 0, encryptlen);
            }
            else
            {
                ecb.Decrypt(tmp, 0, data, 0, encryptlen);
            }
            compressedmem.Write(data, 0, (int)compressedsize);
            adler32 = AdlerCheckSum.GetAdler32(compressedmem, 0, (int)compressedmem.Length);
            filestream.Close();
        }
Пример #6
0
 public void SetECB(string pw)
 {
     byte[] key = System.Text.Encoding.ASCII.GetBytes(pw);
     ecb     = new BlowfishNET.BlowfishECB(key, 0, key.Length);
     komtype = EKomType.encrypt;
 }
Пример #7
0
 public abstract void Convert(BlowfishNET.BlowfishECB ECB, AlgorithmType newalgorithm);