当前位置: 首页>>代码示例>>C#>>正文


C# TripleDESCryptoServiceProvider.CreateDecryptor方法代码示例

本文整理汇总了C#中System.Security.Cryptography.TripleDESCryptoServiceProvider.CreateDecryptor方法的典型用法代码示例。如果您正苦于以下问题:C# TripleDESCryptoServiceProvider.CreateDecryptor方法的具体用法?C# TripleDESCryptoServiceProvider.CreateDecryptor怎么用?C# TripleDESCryptoServiceProvider.CreateDecryptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.TripleDESCryptoServiceProvider的用法示例。


在下文中一共展示了TripleDESCryptoServiceProvider.CreateDecryptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TripleDESKeyWrapDecrypt

        internal static byte[] TripleDESKeyWrapDecrypt (byte[] rgbKey, byte[] rgbEncryptedWrappedKeyData) {
            // Check to see whether the length of the encrypted key is reasonable
            if (rgbEncryptedWrappedKeyData.Length != 32 && rgbEncryptedWrappedKeyData.Length != 40 
                && rgbEncryptedWrappedKeyData.Length != 48) 
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KW_BadKeySize"));

            TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
            // Assume no padding, use CBC mode
            tripleDES.Padding = PaddingMode.None;
            ICryptoTransform dec1 = tripleDES.CreateDecryptor(rgbKey, s_rgbTripleDES_KW_IV);
            byte[] temp2 = dec1.TransformFinalBlock(rgbEncryptedWrappedKeyData, 0, rgbEncryptedWrappedKeyData.Length);
            Array.Reverse(temp2);
            // Get the IV and temp1
            byte[] rgbIV = new byte[8];
            Buffer.BlockCopy(temp2, 0, rgbIV, 0, 8);
            byte[] temp1 = new byte[temp2.Length - rgbIV.Length];
            Buffer.BlockCopy(temp2, 8, temp1, 0, temp1.Length);

            ICryptoTransform dec2 = tripleDES.CreateDecryptor(rgbKey, rgbIV);
            byte[] rgbWKCKS = dec2.TransformFinalBlock(temp1, 0, temp1.Length);

            // checksum the key
            byte[] rgbWrappedKeyData = new byte[rgbWKCKS.Length - 8];
            Buffer.BlockCopy(rgbWKCKS, 0, rgbWrappedKeyData, 0, rgbWrappedKeyData.Length);
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
            byte[] rgbCKS = sha.ComputeHash(rgbWrappedKeyData);
            for (int index = rgbWrappedKeyData.Length, index1 = 0; index < rgbWKCKS.Length; index++, index1++)
                if (rgbWKCKS[index] != rgbCKS[index1])
                    throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_BadWrappedKeySize"));
            return rgbWrappedKeyData;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:31,代码来源:SymmetricKeyWrap.cs

示例2: Decrypt3DES

 public static string Decrypt3DES(string CallPassword, string input, string key)
 {
     if (CallPassword != "ShoveSoft CO.,Ltd -- by Shove 20050709 深圳宝安")
     {
         return "";
     }
     TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
     provider.Key = Encoding.UTF8.GetBytes(key);
     provider.Mode = CipherMode.ECB;
     provider.Padding = PaddingMode.Zeros;
     ICryptoTransform transform = provider.CreateDecryptor();
     byte[] inputBuffer = new byte[input.Length / 2];
     for (int i = 0; i < (input.Length / 2); i++)
     {
         inputBuffer[i] = (byte) Convert.ToInt16(input.Substring(i * 2, 2), 0x10);
     }
     string str = "";
     try
     {
         str = Encoding.UTF8.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length));
     }
     catch
     {
     }
     return TrimSlashZero(str);
 }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:26,代码来源:Encrypt.cs

示例3: Decrypt

        public static String Decrypt(string encryptedString)
        {
            string decyprted = null;
            byte[] inputBytes = null;

            try
            {
                inputBytes = Convert.FromBase64String(encryptedString);
                byte[] pwdhash = null;
                MD5CryptoServiceProvider hashmd5;

                //generate an MD5 hash from the password.
                //a hash is a one way encryption meaning once you generate
                //the hash, you cant derive the password back from it.
                hashmd5 = new MD5CryptoServiceProvider();
                pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
                hashmd5 = null;

                // Create a new TripleDES service provider
                TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
                tdesProvider.Key = pwdhash;
                tdesProvider.Mode = CipherMode.ECB;

                decyprted = ASCIIEncoding.ASCII.GetString(
                    tdesProvider.CreateDecryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length));
            }
            catch(Exception e)
            {
                string str = e.Message;
                throw ;
            }
            return decyprted;
        }
开发者ID:Syryk,项目名称:AspNetSamples,代码行数:33,代码来源:CustomEncryption.cs

示例4: DecryptString

        public static string DecryptString(string message)
        {
            byte[] results;

            // Step 1. We hash the customPassPhrase using MD5
            // We use the MD5 hash generator as the result is a 128 bit byte array
            // which is a valid length for the TripleDES encoder we use below
            var hashProvider = new MD5CryptoServiceProvider();
            byte[] TDESKey = hashProvider.ComputeHash(Encoding.UTF8.GetBytes(customPassPhrase));

            // Step 3. Setup the decoder
            var tripleDESAlgorithm = new TripleDESCryptoServiceProvider() { Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
            tripleDESAlgorithm.Key = TDESKey;

            // Step 4. Convert the input string to a byte[]
            byte[] dataToDecrypt = Convert.FromBase64String(message);

            // Step 5. Attempt to decrypt the string
            try
            {
                ICryptoTransform decryptor = tripleDESAlgorithm.CreateDecryptor();
                results = decryptor.TransformFinalBlock(dataToDecrypt, 0, dataToDecrypt.Length);
                decryptor.Dispose();
            }
            finally
            {
                // Clear the TripleDes and Hashprovider services of any sensitive information
                tripleDESAlgorithm.Clear();
                hashProvider.Clear();
            }

            // Step 6. Return the decrypted string in UTF8 format
            return Encoding.UTF8.GetString(results);
        }
开发者ID:MarcoDorantes,项目名称:spike,代码行数:34,代码来源:hashtextSpec.cs

示例5: Decrypt

 public static string Decrypt(string cypherString, bool useHasing)
 {
     byte[] keyArray;
     byte[] toDecryptArray = Convert.FromBase64String(cypherString);
     string key = "uzma";
     if (useHasing)
     {
         MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
         keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
         hashmd.Clear();
     }
     else
     {
         keyArray = UTF8Encoding.UTF8.GetBytes(key);
     }
     TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
     tDes.Key = keyArray;
     tDes.Mode = CipherMode.ECB;
     tDes.Padding = PaddingMode.PKCS7;
     ICryptoTransform cTransform = tDes.CreateDecryptor();
     try
     {
         byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
         tDes.Clear();
         return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:uzmaha,项目名称:Development-GitHub,代码行数:31,代码来源:CryptorEngine.cs

示例6: Decrypt

        /// <summary>
        /// Decrypts to provided string parameter.
        /// </summary>
        public static string Decrypt(string s)
        {
            if (s == null || s.Length == 0) return string.Empty;

            string result = string.Empty;

            try
            {
                byte[] buffer = Convert.FromBase64String(s);

                TripleDESCryptoServiceProvider des =
                    new TripleDESCryptoServiceProvider();

                MD5CryptoServiceProvider MD5 =
                    new MD5CryptoServiceProvider();

                des.Key =
                    MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));

                des.IV = IV;

                result = Encoding.ASCII.GetString(
                    des.CreateDecryptor().TransformFinalBlock(
                    buffer, 0, buffer.Length));
            }
            catch
            {
                throw;
            }

            return result;
        }
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:35,代码来源:EncryptionClass.cs

示例7: giaiMa

        public static string giaiMa(string strGiaiMa)
        {
            byte[] arrKey;
            byte[] arrMahoa = Convert.FromBase64String(strGiaiMa);
            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            // Lấy giá trị key từ file Web.config
            string keyConfig = (string)settingsReader.GetValue("keyMD5", typeof(String));

            MD5CryptoServiceProvider serviceMD5 = new MD5CryptoServiceProvider();
            arrKey = serviceMD5.ComputeHash(UTF8Encoding.UTF8.GetBytes(keyConfig));
            serviceMD5.Clear(); //Giải phóng tài nguyên
            TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();

            //Thiết lập 1 key cho thuật toán giải mã
            tdsp.Key = arrKey;

            //Chọn phương thức giải mã. Ở đây chúng ta chọn ECB(Electronic code Book) [1]
            tdsp.Mode = CipherMode.ECB;

            //Thêm phương thức giải mã IS010126 (random chuỗi kết quả) [2]
            tdsp.Padding = PaddingMode.ISO10126;

            ICryptoTransform cTransform = tdsp.CreateDecryptor();
            byte[] arrKQ = cTransform.TransformFinalBlock(arrMahoa, 0, arrMahoa.Length);
            tdsp.Clear(); //Giải phóng tài nguyên của TripleDES Encryptor

            // Kết quả giải mã được trả về 1 giá trị kiểu String
            return UTF8Encoding.UTF8.GetString(arrKQ);
        }
开发者ID:quainhankid,项目名称:stationery-management-system,代码行数:29,代码来源:mahoa_giaima.cs

示例8: Decrypt

        //Giai ma  HashMD5 và TripleDES
        public string Decrypt(string cipherString, bool i_blUseHashing)
        {
            byte[] v_arrKey;
            byte[] v_arrEncrypt = new byte[(int)cipherString.Length];
            try
            {
                v_arrEncrypt = Convert.FromBase64String(cipherString);
            }
            catch (Exception v_ex)
            {
                throw v_ex;
            }
            string v_strKey = "fatherofbill";
            if (i_blUseHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                v_arrKey = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(v_strKey));
                hashmd5.Clear();
            }
            else
            {
                v_arrKey = UTF8Encoding.UTF8.GetBytes(v_strKey);
            }
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = v_arrKey;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = tdes.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(v_arrEncrypt, 0, v_arrEncrypt.Length);

            tdes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
开发者ID:sonartez,项目名称:LFS,代码行数:35,代码来源:HashEncryption.cs

示例9: Decrypt

        public static string Decrypt(string value)
        {
            byte[] toDecryptArray = Convert.FromBase64String( value );
            byte[] keyArray = Convert.FromBase64String( Config.Manager.Framework.Encryption.Key );
            byte[] ivArray = Convert.FromBase64String(Config.Manager.Framework.Encryption.IV);

            TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
            tDes.Key = keyArray;
            tDes.Mode = CipherMode.CBC;
            tDes.Padding = PaddingMode.PKCS7;
            tDes.IV = ivArray;

            ICryptoTransform cTransform = tDes.CreateDecryptor();
            try
            {
                byte[] resultArray = cTransform.TransformFinalBlock( toDecryptArray, 0, toDecryptArray.Length );

                tDes.Clear();
                return UTF8Encoding.UTF8.GetString( resultArray, 0, resultArray.Length );
            }
            catch( Exception ex )
            {
                throw ex;
            }
        }
开发者ID:REMSLogic,项目名称:REMSLogic,代码行数:25,代码来源:Encryption.cs

示例10: CreateDecryptor

 public static ICryptoTransform CreateDecryptor(string key, CryptionType type)
 {
     ICryptoTransform transform;
     SHA512 sha512 = new SHA512CryptoServiceProvider();
     var bytes = sha512.ComputeHash(Sha1(key).ToAsciiBytes());
     switch (type)
     {
         case CryptionType.Aes:
             var aes = Rijndael.Create();
             aes.Mode = CipherMode.CBC;
             transform = aes.CreateDecryptor(bytes.Skip(17).Take(32).ToArray(), bytes.Skip(17).Take(16).ToArray());
             aes.Clear();
             break;
         case CryptionType.Des:
             var des = new DESCryptoServiceProvider { Mode = CipherMode.CBC };
             transform = des.CreateDecryptor(bytes.Skip(17).Take(8).ToArray(), bytes.Skip(17).Take(16).ToArray());
             des.Clear();
             break;
         default:
             var tripleDes = new TripleDESCryptoServiceProvider { Mode = CipherMode.CBC };
             transform = tripleDes.CreateDecryptor(bytes.Skip(17).Take(24).ToArray(), bytes.Skip(17).Take(16).ToArray());
             tripleDes.Clear();
             break;
     }
     return transform;
 }
开发者ID:DesmondNgW,项目名称:Web,代码行数:26,代码来源:BaseCryption.cs

示例11: DecryptString

        public static string DecryptString(string Message)
        {
            byte[] Results;
            string passphrase = ReadCert();

            System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
            MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
            byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
            TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
            TDESAlgorithm.Key = TDESKey;
            TDESAlgorithm.Mode = CipherMode.ECB;
            TDESAlgorithm.Padding = PaddingMode.PKCS7;
            byte[] DataToDecrypt = Convert.FromBase64String(Message);
            try
            {
                ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
                Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
            }
            finally
            {
                TDESAlgorithm.Clear();
                HashProvider.Clear();
            }
            return UTF8.GetString(Results);
        }
开发者ID:ranjancse26,项目名称:EHealthCareProviderApp,代码行数:25,代码来源:EncryptDecryptHelper.cs

示例12: DecryptString

        /// <summary>
        /// Decrypts a cipher sting
        /// </summary>
        /// <param name="cipherString">String to decrypt</param>
        /// <returns>Decrypted string</returns>
        public string DecryptString(string cipherString)
        {
            try
            {
                byte[] keyArray;
                byte[] toEncryptArray = Convert.FromBase64String(cipherString);

                System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
                string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();

                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
                tdes.Key = keyArray;
                tdes.Mode = CipherMode.ECB;
                tdes.Padding = PaddingMode.PKCS7;

                ICryptoTransform cTransform = tdes.CreateDecryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

                tdes.Clear();
                return UTF8Encoding.UTF8.GetString(resultArray);
            }
            catch (Exception e)
            {
                Console.WriteLine("DecryptString exception : " + e.ToString());
                return null;
            }
        }
开发者ID:Neeelsie,项目名称:REII422_Desktop,代码行数:36,代码来源:Cryptography.cs

示例13: Decrypt

        public static string Decrypt(string cipherString)
        {
            try
            {
                byte[] keyArray;
                //get the byte code of the string

                byte[] toEncryptArray = Convert.FromBase64String(cipherString);

                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
                hashmd5.Clear();

                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
                tdes.Key = keyArray;
                tdes.Mode = CipherMode.ECB;
                tdes.Padding = PaddingMode.PKCS7;

                ICryptoTransform cTransform = tdes.CreateDecryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(
                                     toEncryptArray, 0, toEncryptArray.Length);
                tdes.Clear();

                return UTF8Encoding.UTF8.GetString(resultArray);
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }
开发者ID:DimitarHPopov,项目名称:CarCommunicator,代码行数:30,代码来源:Utils.cs

示例14: Decrypt

        public string Decrypt(string message)
        {
            byte[] results;
            UTF8Encoding utf8 = new UTF8Encoding();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] deskey = md5.ComputeHash(utf8.GetBytes(Passphrase));
            TripleDESCryptoServiceProvider desalg = new TripleDESCryptoServiceProvider();
            desalg.Key = deskey;
            desalg.Mode = CipherMode.ECB;
            desalg.Padding = PaddingMode.PKCS7;
            byte[] decryptData = Convert.FromBase64String(message);
            try
            {
                //To transform the utf binary code to md5 decrypt
                ICryptoTransform decryptor = desalg.CreateDecryptor();
                results = decryptor.TransformFinalBlock(decryptData, 0, decryptData.Length);
            }
            finally
            {
                desalg.Clear();
                md5.Clear();

            }
            //TO convert decrypted binery code to string
            return utf8.GetString(results);
        }
开发者ID:saditya90,项目名称:MvcPlugin,代码行数:26,代码来源:Helper.cs

示例15: Decrypt

        private const string secureKey = "QaZ1wSx2Edc3RfV4"; //Important Security Key

        #endregion Fields

        #region Methods

        public string Decrypt(string encryptedString)
        {
            try
            {

                byte[] extractBytes = Convert.FromBase64String(encryptedString);   //getting the string to decrypt

                MD5CryptoServiceProvider descObj = new MD5CryptoServiceProvider();  //creating an instance of MD5CryptoServiceProvider
                   byte[] hashCompute = descObj.ComputeHash(UTF8Encoding.UTF8.GetBytes(secureKey));

                    descObj.Clear();  //releasing resourse

                TripleDESCryptoServiceProvider DESCD = new TripleDESCryptoServiceProvider();

                DESCD.Key = hashCompute;  //secure Key is being set

                DESCD.Mode = CipherMode.ECB;     //Electronic Code Book Mode

                DESCD.Padding = PaddingMode.PKCS7;  //Padding

                ICryptoTransform ICTransform = DESCD.CreateDecryptor();
                byte[] finalResult = ICTransform.TransformFinalBlock(                          //Transforming byte array to finalResult
                                     extractBytes, 0, extractBytes.Length);

                DESCD.Clear();

                return UTF8Encoding.UTF8.GetString(finalResult);  //Return Decrypted Text
            }
            catch (Exception ex)
            {
                return ex.ToString();

            }
        }
开发者ID:GauthamAtluri,项目名称:Real-Estate-BookingSystem,代码行数:40,代码来源:Service1.svc.cs


注:本文中的System.Security.Cryptography.TripleDESCryptoServiceProvider.CreateDecryptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。