Beispiel #1
0
        public XVar Encrypt(XVar source)
        {
            if (source.ToString().Length == 0)
            {
                return(source);
            }

            byte[] encrypted;
            using (RijndaelManaged rijndael = new RijndaelManaged())
            {
                rijndael.Key = key;
                rijndael.IV  = INITIALISATION_VECTOR;

                ICryptoTransform encryptor = rijndael.CreateEncryptor();
                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {
                            //Write all data to the stream.
                            swEncrypt.Write(source.ToString());
                        }
                        encrypted = msEncrypt.ToArray();
                    }
                }
            }
            return(MVCFunctions.bin2hex(new XVar(encrypted)));
        }
Beispiel #2
0
        public override XVar addSlashesBinary(dynamic _param_str)
        {
            #region pass-by-value parameters
            dynamic str = XVar.Clone(_param_str);
            #endregion

            return(MVCFunctions.Concat("0x", MVCFunctions.bin2hex((XVar)(str))));
        }
Beispiel #3
0
        /// <summary>
        /// Encrypt string with 3DES algorythm
        /// </summary>
        /// <param name="source">plain value</param>
        /// <returns>encrypted value</returns>
        public XVar Encrypt(XVar source)
        {
            if (String.IsNullOrEmpty(source))
            {
                return(source);
            }
            byte[]    key       = Encoding.ASCII.GetBytes(this.key); //24characters
            byte[]    plainText = Encoding.UTF8.GetBytes(source);
            TripleDES des       = TripleDES.Create();

            des.Key  = key;
            des.Mode = CipherMode.CBC;
            des.IV   = Encoding.ASCII.GetBytes(RunnerCiphererDES.INITIALISATION_VECTOR);
            ICryptoTransform ic = des.CreateEncryptor();

            byte[] encodedText = ic.TransformFinalBlock(plainText, 0, plainText.Length);

            return(MVCFunctions.bin2hex(new XVar(encodedText)));
        }