Beispiel #1
0
 public static void DotestForRC4()
 {
     Console.WriteLine(MyBytes.StringToHexString("test data for test !@#$%^&*()ZXCVBNM<QWERTYUIOASDFGHJK", Encoding.UTF8, HexaDecimal.hex16, ShowHexMode.space));
     Console.WriteLine("RC4 Encrypt");
     byte[] data1 = MyRC4.Encrypt("test data for test !@#$%^&*()ZXCVBNM<QWERTYUIOASDFGHJK", "123", Encoding.UTF8);
     Console.WriteLine(MyBytes.ByteToHexString(data1, HexaDecimal.hex16, ShowHexMode.space));
     data1 = MyRC4.Encrypt("test data for test !@#$%^&*()ZXCVBNM<QWERTYUIOASDFGHJK", "123", Encoding.UTF8);
     Console.WriteLine(MyBytes.ByteToHexString(data1, HexaDecimal.hex16, ShowHexMode.space));
     Console.WriteLine(Convert.ToBase64String(data1));
     Console.WriteLine("RC4 Decrypt");
     byte[] data2 = MyRC4.Decrypt(data1, "123", Encoding.UTF8);
     Console.WriteLine(MyBytes.ByteToHexString(data2, HexaDecimal.hex16, ShowHexMode.space));
     Console.WriteLine(Encoding.UTF8.GetString(data2));
 }
Beispiel #2
0
        /// <summary>
        /// 获取运算后的值,掉用此法的该版本的重载将会改变涉及到的staticData数据的游标
        /// </summary>
        /// <param name="yourActuatorStaticDataCollection">可用staticData集合</param>
        /// <param name="yourDataResultCollection">返回对所有staticData数据运算后的结果列表</param>
        /// <param name="errorMessage">错误消息(如果没有错误则为null)(在获取参数化数据产生错误后因对当前case设置警示)</param>
        /// <returns>运算结果</returns>
        public string GetTargetContentData(ActuatorStaticDataCollection yourActuatorStaticDataCollection, NameValueCollection yourDataResultCollection, out string errorMessage)
        {
            string myTargetContentData = contentData;

            errorMessage = null;
            if (hasParameter)
            {
                myTargetContentData = ParameterizationContentHelper.GetCurrentParametersData(contentData, MyConfiguration.ParametersDataSplitStr, yourActuatorStaticDataCollection, yourDataResultCollection, out errorMessage);
            }
            if (encodetype != ParameterizationContentEncodingType.encode_default)
            {
                switch (encodetype)
                {
                //base64
                case ParameterizationContentEncodingType.encode_base64:
                    myTargetContentData = Convert.ToBase64String(Encoding.UTF8.GetBytes(myTargetContentData));
                    break;

                case ParameterizationContentEncodingType.decode_base64:
                    try
                    {
                        myTargetContentData = Encoding.UTF8.GetString(Convert.FromBase64String(myTargetContentData));
                    }
                    catch (Exception ex)
                    {
                        myTargetContentData = "ContentEncoding Error:" + ex.Message;
                    }
                    break;

                //hex 16
                case ParameterizationContentEncodingType.encode_hex16:
                    myTargetContentData = MyBytes.StringToHexString(myTargetContentData);
                    break;

                case ParameterizationContentEncodingType.decode_hex16:
                    try
                    {
                        byte[] nowBytes = MyBytes.HexStringToByte(myTargetContentData, HexDecimal.hex16, ShowHexMode.space);
                        myTargetContentData = Encoding.UTF8.GetString(nowBytes);
                    }
                    catch (Exception ex)
                    {
                        myTargetContentData = "ContentEncoding Error:" + ex.Message;
                    }
                    break;

                //hex 2
                case ParameterizationContentEncodingType.encode_hex2:
                    myTargetContentData = MyBytes.StringToHexString(myTargetContentData, Encoding.UTF8, HexDecimal.hex2, ShowHexMode.space);
                    break;

                case ParameterizationContentEncodingType.decode_hex2:
                    try
                    {
                        byte[] nowBytes = MyBytes.HexStringToByte(myTargetContentData, HexDecimal.hex2, ShowHexMode.space);
                        myTargetContentData = Encoding.UTF8.GetString(nowBytes);
                    }
                    catch (Exception ex)
                    {
                        myTargetContentData = "ContentEncoding Error:" + ex.Message;
                    }
                    break;

                default:
                    errorMessage = "[getTargetContentData] unknow or not supported this encodetype";
                    break;
                }
            }
            return(myTargetContentData);
        }