• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cryptography.TripleDESCryptoServiceProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TripleDESCryptoServiceProvider类属于System.Security.Cryptography命名空间,在下文中一共展示了TripleDESCryptoServiceProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Decodificar

        public static string Decodificar(string entrada)
        {
            TripleDESCryptoServiceProvider tripledescryptoserviceprovider = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider md5cryptoserviceprovider = new MD5CryptoServiceProvider();

            try
            {
                if (entrada.Trim() != "")
                {
                    string chave = "asdfg";
                    tripledescryptoserviceprovider.Key = md5cryptoserviceprovider.ComputeHash(Encoding.Default.GetBytes(chave));
                    tripledescryptoserviceprovider.Mode = CipherMode.ECB;
                    ICryptoTransform desdencrypt = tripledescryptoserviceprovider.CreateDecryptor();
                    byte[] buff = Convert.FromBase64String(entrada);

                    return Encoding.Default.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length));
                }
                else
                {
                    return "";
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Erro" + exception.Message);
                throw exception;
            }
            finally
            {
                tripledescryptoserviceprovider = null;
                md5cryptoserviceprovider = null;
            }
        }
开发者ID:Ewertton,项目名称:Read-Write-Qr,代码行数:33,代码来源:FrmReadQr.cs


示例2: Encrypt

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strToEncrypt"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public static string Encrypt(string strToEncrypt, string key)
        {
            try
            {
                TripleDESCryptoServiceProvider crypto = new TripleDESCryptoServiceProvider();
                MD5CryptoServiceProvider hash = new MD5CryptoServiceProvider();

                byte[] byteHash, byteBuff;

                string strTempKey = key;

                byteHash = hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
                hash = null;

                crypto.Key = byteHash;
                crypto.Mode = CipherMode.ECB; //CBC, CFB

                byteBuff = ASCIIEncoding.ASCII.GetBytes(strToEncrypt);

                return Convert.ToBase64String(crypto.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
            }
            catch (Exception ex)
            {
                throw new Exception("Error: " + ex.Message + ".\n Encryption Failed. Please try again.");
            }
        }
开发者ID:sameesh-s,项目名称:stego-app,代码行数:33,代码来源:Text.cs


示例3: Encrypt

        public static string Encrypt(String plainText )
        {
            string encrypted = null;
            try
            {
                byte[] inputBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
                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;

                encrypted = Convert.ToBase64String(
                    tdesProvider.CreateEncryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length));
            }
            catch(Exception e)
            {
                string str = e.Message;
                throw ;
            }
            return encrypted;
        }
开发者ID:Syryk,项目名称:AspNetSamples,代码行数:31,代码来源:CustomEncryption.cs


示例4: Encrypt

        /// <summary>
        /// Encrypt a string using dual encryption method. Return a encrypted cipher Text
        /// </summary>
        /// <param name="toEncrypt">string to be encrypted</param>
        /// <param name="useHashing">use hashing? send to for extra secirity</param>
        /// <returns></returns>
        public static string Encrypt(string toEncrypt, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            // Get the key from config file
            string key = SecurityKey;
            //System.Windows.Forms.MessageBox.Show(key);
            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.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.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tdes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }
开发者ID:nhannhan159,项目名称:room-management4,代码行数:34,代码来源:CryptorEngine.cs


示例5: EncryptString

        public static string EncryptString(string Message)
        {
            byte[] results;

            var hashProvider = new MD5CryptoServiceProvider();
            var tripleDESAlgorithm = new TripleDESCryptoServiceProvider() { Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
            tripleDESAlgorithm.Key = hashProvider.ComputeHash(Encoding.UTF8.GetBytes(customPassPhrase));

            byte[] dataToEncrypt = Encoding.UTF8.GetBytes(Message);

            try
            {
                ICryptoTransform encryptor = tripleDESAlgorithm.CreateEncryptor();
                results = encryptor.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
                encryptor.Dispose();
            }
            finally
            {
                // Clear the TripleDes and Hashprovider services of any sensitive information
                tripleDESAlgorithm.Clear();
                hashProvider.Clear();
            }

            return Convert.ToBase64String(results);
        }
开发者ID:MarcoDorantes,项目名称:spike,代码行数:25,代码来源:hashtextSpec.cs


示例6: GetCriptografiaSimetrica

        /// <summary>
        /// A chave deve possuir 16 com caracteres "1234567890123456"
        /// </summary>
        /// <param name="str"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCriptografiaSimetrica(this string str, string key)
        {
            using (TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider())
            {

                provider.Mode = CipherMode.CFB;
                provider.Padding = PaddingMode.PKCS7;

                MemoryStream mStream = new MemoryStream();

                CryptoStream cs = new CryptoStream(mStream, provider.CreateEncryptor(Encoding.UTF8.GetBytes(key), new byte[] { 138, 154, 251, 188, 64, 108, 167, 121 }), CryptoStreamMode.Write);

                byte[] toEncrypt = new UTF8Encoding().GetBytes(str);

                cs.Write(toEncrypt, 0, toEncrypt.Length);
                cs.FlushFinalBlock();
                byte[] ret = mStream.ToArray();

                mStream.Close();
                cs.Close();

                str = Convert.ToBase64String(ret);

            }


            return str;
        }
开发者ID:mvasilva,项目名称:MvasilvaFramework,代码行数:34,代码来源:CryptoProvider.cs


示例7: 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


示例8: EncryptString

        public static string EncryptString(string needToEncrypt)
        {
            string encryptedstring;
            try
            {

                // Create a new instance of the TripleDESCryptoServiceProvider
                // class.  This generates a new key and initialization
                // vector (IV).
                using (TripleDESCryptoServiceProvider myTripleDES = new TripleDESCryptoServiceProvider())
                {
                    myTripleDES.Key = StringToByteArray(HttpContext.GetGlobalResourceObject("Global", "Key").ToString());
                    myTripleDES.IV = StringToByteArray(HttpContext.GetGlobalResourceObject("Global", "IV").ToString());
                    // Encrypt the string to an array of bytes.
                    byte[] encrypted = EncryptStringToBytes(needToEncrypt, myTripleDES.Key, myTripleDES.IV);
                    encryptedstring = ByteArrayToString(encrypted);

                    // Decrypt the bytes to a string.

                    string roundtrip2 = DecryptStringFromBytes(StringToByteArray(encryptedstring), myTripleDES.Key, myTripleDES.IV);

                }
                return encryptedstring;

            }
            catch (Exception ex)
            {
                return null;
            }
        }
开发者ID:menasbeshay,项目名称:ivalley-svn,代码行数:30,代码来源:General.cs


示例9: DecryptKey

        public static AptimaLicenseInfo DecryptKey(string licenseKey, string securityKey, int inputStringLength)
        {
            ////Decrypt

            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(licenseKey);
 
            keyArray = UTF8Encoding.UTF8.GetBytes(securityKey);

            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();
            string outputString = UTF8Encoding.UTF8.GetString(resultArray);
            if (outputString.Length != inputStringLength)
            {//invalid output string! 
                return new AptimaLicenseInfo("Invalid license key! (Return string has incorrect length)");
            }

            ////populate

            return PopulateLicenseInfo(outputString);            
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:28,代码来源:AptimaEncryptor.cs


示例10: TDesTest_EncryptUpdate

        public MFTestResults TDesTest_EncryptUpdate()
        {
            MFTestResults res;

            try
            {
                using (TripleDESCryptoServiceProvider csp = new TripleDESCryptoServiceProvider())
                {
                    res = SymmetricTestHelper.Test_EncryptUpdate(csp);
                }

                if (res == MFTestResults.Pass && m_isEmulator)
                {
                    using (TripleDESCryptoServiceProvider csp = new TripleDESCryptoServiceProvider("Emulator_Crypto"))
                    {
                        res = SymmetricTestHelper.Test_EncryptUpdate(csp);
                    }
                }
            }
            catch
            {
                return MFTestResults.Fail;
            }

            return res;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:26,代码来源:TDesTests.cs


示例11: Decrypt

        public static string Decrypt(string cypherString)
        {
            byte[] keyArray;
            byte[] toDecryptArray = StringToByteArray(cypherString);

            MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
            keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(ENCRYPTION_KEY));
            hashmd.Clear();

            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:gertgjoka,项目名称:fashion-commerce,代码行数:26,代码来源:Encryption.cs


示例12: ReadFile

        /// <summary>
        /// Ghi license ra file
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public static string ReadFile(string FilePath)
        {
            try
            {
                FileInfo fi = new FileInfo(FilePath);
                if (fi.Exists == false)
                    return string.Empty;

                FileStream fin = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
                TripleDES tdes = new TripleDESCryptoServiceProvider();
                CryptoStream cs = new CryptoStream(fin, tdes.CreateDecryptor(key, iv), CryptoStreamMode.Read);

                StringBuilder SB = new StringBuilder();
                int ch;
                for (int i = 0; i < fin.Length; i++)
                {
                    ch = cs.ReadByte();
                    if (ch == 0)
                        break;
                    SB.Append(Convert.ToChar(ch));
                }

                cs.Close();
                fin.Close();
                return SB.ToString();
            }
            catch(Exception ex)
            {
                return "";
            }
        }
开发者ID:romeobk,项目名称:HRMS_7Cua,代码行数:36,代码来源:FileReadWrite.cs


示例13: Decrypt

 public static string Decrypt(string cipherText, string passPhrase)
 {
     try
     {
         TripleDESCryptoServiceProvider objDESCrypto =
             new TripleDESCryptoServiceProvider();
         MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
         byte[] byteHash, byteBuff;
         string strTempKey = passPhrase;
         byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
         objHashMD5 = null;
         objDESCrypto.Key = byteHash;
         objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
         byteBuff = Convert.FromBase64String(cipherText);
         string strDecrypted = ASCIIEncoding.ASCII.GetString
         (objDESCrypto.CreateDecryptor().TransformFinalBlock
         (byteBuff, 0, byteBuff.Length));
         objDESCrypto = null;
         return strDecrypted;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
开发者ID:TokleMahesh,项目名称:BG,代码行数:25,代码来源:StringCipher.cs


示例14: Decrypt

        /// <summary>
        /// Returns a decrypted string by a key
        /// </summary>
        /// <remarks>
        /// If something is broken this method returns an empty string
        /// </remarks>
        /// <param name="text">Text to decrypt</param>
        /// <param name="key">Key to decrypt</param>
        /// <param name="encoding" >Encoding to get bytes. UTF8 by default.</ param >
        /// <returns></returns>
        public static String Decrypt(String textoEncriptado, String clave, Encoding encoding = null)
        {
            try
            {
                if (String.IsNullOrEmpty(textoEncriptado) || String.IsNullOrEmpty(clave))
                    return String.Empty;

                byte[] keyBytes;
                byte[] encryptedBytes = Convert.FromBase64String(textoEncriptado);

                //Create a MD5 object to obtain a hash
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();

                keyBytes = hashmd5.ComputeHash(encoding.GetBytes(clave));
                hashmd5.Clear();

                //Create a Triple DES object to decrypt
                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

                tdes.Key = keyBytes;
                tdes.Mode = CipherMode.ECB;
                tdes.Padding = PaddingMode.PKCS7;

                ICryptoTransform cTransform = tdes.CreateDecryptor();

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

                return encoding.GetString(resultArray);
            }
            catch (Exception)
            {
                return String.Empty;
            }
        }
开发者ID:JuanGRomeo,项目名称:Utility,代码行数:45,代码来源:Security.cs


示例15: Encrypt

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

            string result = string.Empty;

            try
            {
                byte[] buffer = Encoding.ASCII.GetBytes(s);

                TripleDESCryptoServiceProvider des =
                    new TripleDESCryptoServiceProvider();

                MD5CryptoServiceProvider MD5 =
                    new MD5CryptoServiceProvider();

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

                des.IV = IV;
                result = Convert.ToBase64String(
                    des.CreateEncryptor().TransformFinalBlock(
                        buffer, 0, buffer.Length));
            }
            catch
            {
                throw;
            }

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


示例16: Encrypt

        public static string Encrypt(string ToEncrypt, bool useHasing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(ToEncrypt);

            string Key = "malkit";
            if (useHasing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
                hashmd5.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.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tDes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:25,代码来源:Utility.cs


示例17: GetDescriptografiaSimetrica

        /// <summary>
        /// A chave deve possuir 16 com caracteres "1234567890123456"
        /// </summary>
        /// <param name="str"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetDescriptografiaSimetrica(this string str, string key)
        {
            using (TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider())
            {


                provider.Mode = CipherMode.CFB;
                provider.Padding = PaddingMode.PKCS7;
                byte[] inputEquivalent = Convert.FromBase64String(str);

                MemoryStream msDecrypt = new MemoryStream();

                CryptoStream csDecrypt = new CryptoStream(msDecrypt, provider.CreateDecryptor(Encoding.UTF8.GetBytes(key), new byte[] { 138, 154, 251, 188, 64, 108, 167, 121 }), CryptoStreamMode.Write);
                csDecrypt.Write(inputEquivalent, 0, inputEquivalent.Length);
                csDecrypt.FlushFinalBlock();

                csDecrypt.Close();

                str = Encoding.UTF8.GetString(msDecrypt.ToArray());
                msDecrypt.Close();
            }


            return str;
        }
开发者ID:mvasilva,项目名称:MvasilvaFramework,代码行数:31,代码来源:CryptoProvider.cs


示例18: TripleDESKeyWrapEncrypt

        //
        // internal static methods
        //

        // CMS TripleDES KeyWrap as described in "http://www.w3.org/2001/04/xmlenc#kw-tripledes"
        internal static byte[] TripleDESKeyWrapEncrypt (byte[] rgbKey, byte[] rgbWrappedKeyData) {
            // checksum the key
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
            byte[] rgbCKS = sha.ComputeHash(rgbWrappedKeyData);

            // generate a random IV
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] rgbIV = new byte[8];
            rng.GetBytes(rgbIV);

            // rgbWKCS = rgbWrappedKeyData | (first 8 bytes of the hash)
            byte[] rgbWKCKS = new byte[rgbWrappedKeyData.Length + 8];
            TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
            // Don't add padding, use CBC mode: for example, a 192 bits key will yield 40 bytes of encrypted data
            tripleDES.Padding = PaddingMode.None;
            ICryptoTransform enc1 = tripleDES.CreateEncryptor(rgbKey, rgbIV);
            Buffer.BlockCopy(rgbWrappedKeyData, 0, rgbWKCKS, 0, rgbWrappedKeyData.Length);
            Buffer.BlockCopy(rgbCKS, 0, rgbWKCKS, rgbWrappedKeyData.Length, 8);
            byte[] temp1 = enc1.TransformFinalBlock(rgbWKCKS, 0, rgbWKCKS.Length);
            byte[] temp2 = new byte[rgbIV.Length + temp1.Length];
            Buffer.BlockCopy(rgbIV, 0, temp2, 0, rgbIV.Length);
            Buffer.BlockCopy(temp1, 0, temp2, rgbIV.Length, temp1.Length);
            // temp2 = REV (rgbIV | E_k(rgbWrappedKeyData | rgbCKS))
            Array.Reverse(temp2);

            ICryptoTransform enc2 = tripleDES.CreateEncryptor(rgbKey, s_rgbTripleDES_KW_IV);
            return enc2.TransformFinalBlock(temp2, 0, temp2.Length);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:33,代码来源:SymmetricKeyWrap.cs


示例19: Decrypt

        /// <summary>
        /// DeCrypt a string using dual encryption method. Return a DeCrypted clear string
        /// </summary>
        /// <param name="cipherString">encrypted string</param>
        /// <param name="useHashing">Did you use hashing to encrypt this data? pass true is yes</param>
        /// <returns></returns>
        public static string Decrypt(string cipherString, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(cipherString);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            //Get your key from config file to open the lock!
            string key = SecurityKey;

            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.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();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            tdes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
开发者ID:nhannhan159,项目名称:room-management4,代码行数:35,代码来源:CryptorEngine.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Pkcs.CmsSigner类代码示例发布时间:2022-05-26
下一篇:
C# Cryptography.SymmetricAlgorithm类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap