示例#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);