Ejemplo n.º 1
0
        public static string Encrypt(string cryptoMethod, string txt)
        {
            string retVal = String.Empty;

            try
            {
                CryptoType ct;
                Enum.TryParse(cryptoMethod, true, out ct);

                CryptoCollection cc  = CryptoCollection.GetCryptoCollectionInfoByMethod(cryptoMethod);
                string           key = genRandomText(cc.Key);
                string           iv  = genRandomText(cc.IV);
                string           e   = Encrypt(ct, txt, key, iv);

                int i = (int)e.FirstOrDefault();

                key = String.Join(String.Empty, key.Reverse().ToArray());
                iv  = String.Join(String.Empty, iv.Reverse().ToArray());

                if (i < e.Length)
                {
                    e = e.Substring(0, i) + key + iv + e.Substring(i);
                }
                else
                {
                    e += key + iv;
                }

                retVal = "[" + cc.ID + "]" + e;
            }
            catch
            {
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        public static string Encrypts(string cryptoMethod, string txt)
        {
            string retVal = String.Empty;

            try
            {
                CryptoType ct;
                Enum.TryParse(cryptoMethod, out ct);

                CryptoCollection cc = CryptoCollection.GetCryptoCollectionInfoByMethod(cryptoMethod);

                //retVal = Encrypt(cryptoMethod, txt, cc);
            }
            catch
            {
            }
            return(retVal);
        }
Ejemplo n.º 3
0
        public static string Decrypt(string txt)
        {
            string retVal = String.Empty;

            try
            {
                CryptoCollection cc = CryptoCollection.GetCryptoCollectionInfoByID(txt.Substring(1, 3));

                CryptoType ct;
                Enum.TryParse(cc.Method, out ct);

                int    i   = (int)Convert.ToChar(txt.Substring(5, 1));
                string d   = String.Empty;
                string key = String.Empty;
                string iv  = String.Empty;

                if (i < (txt.Length - cc.Key - cc.IV))
                {
                    d   = txt.Substring(5, i) + txt.Substring(5 + i + cc.Key + cc.IV);
                    key = txt.Substring(5 + i, cc.Key);
                    iv  = txt.Substring(5 + i + cc.Key, cc.IV);
                }
                else
                {
                    d   = txt.Substring(5, txt.Length - cc.Key - cc.IV - 5);
                    key = txt.Substring(txt.Length - cc.Key - cc.IV, cc.Key);
                    iv  = txt.Substring(txt.Length - cc.IV);
                }

                key = String.Join(String.Empty, key.Reverse().ToArray());
                iv  = String.Join(String.Empty, iv.Reverse().ToArray());

                retVal = Decrypt(ct, d, key, iv);
            }
            catch
            {
            }
            return(retVal);
        }