Exemplo n.º 1
0
        public static string Decrypt(string strEncrypted)
        {
            string retValue = string.Empty;

            try
            {
                TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
                MD5CryptoServiceProvider       objHashMD5   = new MD5CryptoServiceProvider();
                byte[] byteHash, byteBuff;
                string strTempKey = ConvertTool.strtoHex("DReportPassword");
                byteHash          = objHashMD5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strTempKey));
                objHashMD5        = null;
                objDESCrypto.Key  = byteHash;
                objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
                byte[] _key0 = Encoding.Unicode.GetBytes(strEncrypted.Substring(0, 8));
                byte[] _key1 = Encoding.Unicode.GetBytes("20100723");
                string ffdd  = ConvertTool.Hextostr(strEncrypted.Substring(8));
                byteBuff = Convert.FromBase64String(ffdd);
                string strDecrypted = UTF8Encoding.UTF8.GetString(objDESCrypto.CreateDecryptor(_key0, _key1).TransformFinalBlock(byteBuff, 0, byteBuff.Length));
                objDESCrypto = null;
                retValue     = strDecrypted;
            }
            catch (Exception ex)
            {
                retValue = "error: " + ex.Message;
            }
            return(retValue);
        }
Exemplo n.º 2
0
        public static string Encrypt(string strToEncrypt)
        {
            string retValue = string.Empty;

            try
            {
                TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
                MD5CryptoServiceProvider       objHashMD5   = new MD5CryptoServiceProvider();
                byte[] byteHash, byteBuff;
                string strTempKey = ConvertTool.strtoHex("DReportPassword");
                byteHash          = objHashMD5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strTempKey));
                objHashMD5        = null;
                objDESCrypto.Key  = byteHash;
                objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
                string _key  = ConvertTool.GetUniqueKey(8);
                byte[] _key0 = Encoding.Unicode.GetBytes(_key);
                byte[] _key1 = Encoding.Unicode.GetBytes("20100723");
                byteBuff = UTF8Encoding.UTF8.GetBytes(strToEncrypt);
                string base64str = Convert.ToBase64String(objDESCrypto.CreateEncryptor(_key0, _key1).TransformFinalBlock(byteBuff, 0, byteBuff.Length));
                retValue = _key + ConvertTool.strtoHex(base64str);
            }
            catch (Exception ex)
            {
                retValue = "error: " + ex.Message;
            }
            return(retValue);
        }