Exemplo n.º 1
0
        public static void DoTestChiper()
        {
            var chiper = new CfbDCPCipher(new BlowfishEngine(), 8);
            chiper.Init(false, Key);
            //"RA3545RQa5d+xGPLAw==0"
            var b = System.Text.Encoding.ASCII.GetBytes("RA3545RQa5d+xGPLAw==");
            byte[] bDecoded = Base64.Decode(b);
            var decodedString2 = new byte[13];
            if (bDecoded != null)
                if (chiper.ProcessBlock(bDecoded, 0, decodedString2, 0) != 13)
                    throw new SystemException("Topor vsplil!");
                else
                    throw new SystemException("Decoded string is null!");

            var str2 = System.Text.Encoding.ASCII.GetString(decodedString2);
            if (str2 != "192.168.1.123")
                throw new SystemException("failed");
        }
Exemplo n.º 2
0
        private static byte[] ReadBytes(ref int bt, Byte[] mem)
        {
            if (bt + sizeof(int) > mem.Length)
                throw new SystemException("Size of string is greater that expected");

            var chiper = new CfbDCPCipher(new BlowfishEngine(), 8);
            chiper.Init(false, Key);

            int stringSize = BitConverter.ToInt32(mem, bt);

            if (bt + sizeof(int) + stringSize > mem.Length)
                throw new SystemException("String is greater that expected");

            var b = new byte[stringSize - 1];
            Array.Copy(mem, bt + 4, b, 0, stringSize - 1);
            byte[] bDecoded = Base64.Decode(b);
            var decodedBytes = new byte[bDecoded.Length];
            chiper.ProcessBlock(bDecoded, 0, decodedBytes, 0);
            bt += stringSize + 4;
            return decodedBytes;
        }
Exemplo n.º 3
0
        private static byte[] EncodeBytes(Byte[] value, KeyParameter key)
        {
            var chiper = new CfbDCPCipher(new BlowfishEngine(), 8);
            if (key != null)
                chiper.Init(true, key);
            else
                chiper.Init(true, Key);

            var encodedBytes = new byte[value.Length];
            var totalBytes = chiper.ProcessBlock(value, 0, encodedBytes, 0);

            var b = new byte[totalBytes];
            Array.Copy(encodedBytes, 0, b, 0, totalBytes);
            var encoded = Base64.Encode(b);
            return encoded;
        }