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


C# TripleDESCryptoServiceProvider.CreateEncryptor方法代码示例

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


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

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

示例2: Encrypt3DES

        /// <summary>
        /// 加密 Base64(3DES(加密内容))
        /// </summary>
        /// <param name="content"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Encrypt3DES(string content, string key)
        {
            string result = string.Empty;
            try
            {
                TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
                byte[] buffer3 = Encoding.GetEncoding("utf-8").GetBytes(content);
                provider.Key = Encoding.GetEncoding("utf-8").GetBytes(key);
                provider.Mode = CipherMode.ECB;
                MemoryStream stream = new MemoryStream();
                ICryptoTransform transform = provider.CreateEncryptor();
                CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
                stream2.Write(buffer3, 0, buffer3.Length);
                stream2.FlushFinalBlock();
                result = System.Convert.ToBase64String(stream.ToArray());
                stream.Flush();
                stream.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Encryption.Encrypt3DES(string, string) :: " + ex.Message);
                throw ex;
            }

            return result;
        }
开发者ID:JimmyFung,项目名称:DesktopHelper,代码行数:32,代码来源:Encryption.cs

示例3: cooking

        public msgMaid cooking(byte[] otama)
        {
            //メイドオブジェクト
            msgMaid m = new msgMaid();

            //DESC
            TripleDESCryptoServiceProvider frill = new TripleDESCryptoServiceProvider();

            // Triple DES のサービス プロバイダを生成します
            TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();

            //取得
            m.houshinokokoro = frill.Key;
            m.zettaifukujyu = frill.IV;

            // source 配列から cryptData 配列へ変換
            // 文字列を byte 配列に変換します
            //byte[] source = Encoding.Unicode.GetBytes(cachusha);

            // 入出力用のストリームを生成します
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(m.houshinokokoro, m.zettaifukujyu), CryptoStreamMode.Write))
                {
                    // ストリームに暗号化するデータを書き込みます
                    cs.Write(otama, 0, otama.Length);
                }

                // 暗号化されたデータを byte 配列で取得します
                m.zenryokushugo = ms.ToArray();
            }

            // byte 配列を文字列に変換して表示します
            return m;
        }
开发者ID:yuta1011tokyo,项目名称:Liplis-Windows,代码行数:35,代码来源:LiplisMaidSystem.cs

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

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

示例6: maHoa

        public static string maHoa(string strMaHoa)
        {
            byte[] arrKey;
            byte[] arrMahoa = UTF8Encoding.UTF8.GetBytes(strMaHoa);

            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 mã hóa
            tdsp.Key = arrKey;

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

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

            ICryptoTransform cTransform = tdsp.CreateEncryptor();
            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ả mã hóa được trả về 1 giá trị kiểu String
            return Convert.ToBase64String(arrKQ, 0, arrKQ.Length);
        }
开发者ID:quainhankid,项目名称:stationery-management-system,代码行数:30,代码来源:mahoa_giaima.cs

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

示例8: CryptString

        public static string CryptString(string val)
        {
            TripleDESCryptoServiceProvider dprov = new TripleDESCryptoServiceProvider();

            dprov.BlockSize = 64;
            dprov.KeySize = 192;
            byte[] IVBuf = BitConverter.GetBytes(DESIV);
            byte[] keyBuf = new byte[24];
            byte[] keyB0 = BitConverter.GetBytes(DESkey[0]);
            byte[] keyB1 = BitConverter.GetBytes(DESkey[1]);
            byte[] keyB2 = BitConverter.GetBytes(DESkey[2]);
            for (int i = 0; i < 8; i++) keyBuf[i] = keyB0[i];
            for (int i = 0; i < 8; i++) keyBuf[i + 8] = keyB1[i];
            for (int i = 0; i < 8; i++) keyBuf[i + 16] = keyB2[i];

            ICryptoTransform ict = dprov.CreateEncryptor(keyBuf, IVBuf);

            System.IO.MemoryStream mstream = new System.IO.MemoryStream();
            CryptoStream cstream = new CryptoStream(mstream, ict, CryptoStreamMode.Write);

            byte[] toEncrypt = new ASCIIEncoding().GetBytes(val);

            // Write the byte array to the crypto stream and flush it.
            cstream.Write(toEncrypt, 0, toEncrypt.Length);
            cstream.FlushFinalBlock();

            byte[] ret = mstream.ToArray();

            cstream.Close();
            mstream.Close();

            return Convert.ToBase64String(ret);
        }
开发者ID:bneuhold,项目名称:EFQM,代码行数:33,代码来源:Encryption64Util.cs

示例9: enc

 public void enc(string file, string keyfile)
 {
     string tmphst = @"C:\Program Files\NiCoding\hst.tmp";
     FileStream fsFileOut = File.Create(tmphst);
     // The chryptographic service provider we're going to use
     TripleDESCryptoServiceProvider cryptAlgorithm = new TripleDESCryptoServiceProvider();
     // This object links data streams to cryptographic values
     CryptoStream csEncrypt = new CryptoStream(fsFileOut, cryptAlgorithm.CreateEncryptor(), CryptoStreamMode.Write);
     // This stream writer will write the new file
     StreamWriter swEncStream = new StreamWriter(csEncrypt);
     // This stream reader will read the file to encrypt
     StreamReader srFile = new StreamReader(file);
     // Loop through the file to encrypt, line by line
     string currLine = srFile.ReadLine();
     while (currLine != null)
     {
         // Write to the encryption stream
         swEncStream.Write(currLine);
         currLine = srFile.ReadLine();
     }
     // Wrap things up
     srFile.Close();
     swEncStream.Flush();
     swEncStream.Close();
     // Create the key file
     FileStream fsFileKey = File.Create(@"C:\Program Files\NiCoding\RipLeech\"+keyfile+".rdat");
     BinaryWriter bwFile = new BinaryWriter(fsFileKey);
     bwFile.Write(cryptAlgorithm.Key);
     bwFile.Write(cryptAlgorithm.IV);
     bwFile.Flush();
     bwFile.Close();
     filecleanup(tmphst, file);
 }
开发者ID:Gigawiz,项目名称:NiFuscate,代码行数:33,代码来源:FileEncryption.cs

示例10: Encrypt

        public static string Encrypt(this string plainText, string encryptionKey)
        {
            var toEncryptArray = Encoding.ASCII.GetBytes(plainText);

            byte[] encryptionKeyArray;

            // get MD5 has for the key
            using (var hashmd5 = new MD5CryptoServiceProvider())
            {
                encryptionKeyArray = hashmd5.ComputeHash(Encoding.ASCII.GetBytes(encryptionKey));
                hashmd5.Clear();
            }

            byte[] resultArray;

            // Set the secret key for the tripleDES algorithm
            using (
                var tdes = new TripleDESCryptoServiceProvider
                {
                    Key = encryptionKeyArray,
                    Mode = CipherMode.ECB,
                    Padding = PaddingMode.PKCS7
                })
            {
                // Transform the specified region of bytes array to resultArray
                var cTransform = tdes.CreateEncryptor();
                resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                tdes.Clear();
            }

            // Return the encrypted data into unreadable string format
            return Convert.ToBase64String(resultArray);
        }
开发者ID:arul141890,项目名称:ScriptGenerator,代码行数:33,代码来源:Encryptor.cs

示例11: ToCipherText

 public static string ToCipherText(this string clearText)
 {
     TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
     byte[] clearBytes = Encoding.UTF8.GetBytes(clearText);
     byte[] foggyBytes = Transform(clearBytes, provider.CreateEncryptor(key, initVector));
     return Convert.ToBase64String(foggyBytes);
 }
开发者ID:thekane,项目名称:identity-server-3-samples,代码行数:7,代码来源:EncryptionHelper.cs

示例12: mEncriptar

        public string mEncriptar(string strToEncrypt)
        {
            string Key = ppKeyEncriptar;
            string IV = ppIVEncriptar;

            MemoryStream output = new MemoryStream();
            byte[] byteData = new UnicodeEncoding().GetBytes(strToEncrypt);

            TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
            byte[] desKey = new byte[Key.Length / 2];

            for (int i = 0; i < Key.Length; i += 2)
            {
                desKey[i / 2] = byte.Parse(Key.Substring(i, 2), NumberStyles.HexNumber);
            }

            byte[] desIV = new byte[IV.Length / 2];
            for (int i = 0; i < IV.Length; i += 2)
            {
                desIV[i / 2] = byte.Parse(IV.Substring(i, 2), NumberStyles.HexNumber);
            }

            CryptoStream crypt = new CryptoStream(output, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
            crypt.Write(byteData, 0, byteData.Length);
            crypt.Close(); output.Close();

            byte[] bin = output.ToArray();
            return Convert.ToBase64String(bin);
        }
开发者ID:daguilae,项目名称:MRP,代码行数:29,代码来源:EncriptionController.cs

示例13: Encrypt

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

                // Get the key from config file
                string key = SystemStatements.SECURITY_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);
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:cronkite-asu,项目名称:SeedSpeak,代码行数:39,代码来源:Security.cs

示例14: EncryptPassword

        public static string EncryptPassword(string password)
        {
            string outParam = null;

            try
            {
                byte[] keyMD5Hash;
                byte[] passwordBytes;

                MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();
                keyMD5Hash = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
                hashMD5 = null;

                TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
                tripleDES.Key = keyMD5Hash;
                tripleDES.Mode = CipherMode.ECB;

                passwordBytes = ASCIIEncoding.ASCII.GetBytes(password);

                outParam = Convert.ToBase64String(tripleDES.CreateEncryptor().TransformFinalBlock(passwordBytes, 0, passwordBytes.Length));

                tripleDES = null;
            }
            catch (Exception)
            {
                outParam = null;
            }

            return outParam;
        }
开发者ID:rapline,项目名称:DotNET,代码行数:30,代码来源:Encrypt.cs

示例15: Encrypt

        public static string Encrypt(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;//to  pass encode key
            desalg.Mode = CipherMode.ECB;
            desalg.Padding = PaddingMode.PKCS7;
            byte[] encrypt_data = utf8.GetBytes(message);
            try
            {
                ICryptoTransform encryptor = desalg.CreateEncryptor();
                results = encryptor.TransformFinalBlock(encrypt_data, 0, encrypt_data.Length);
            }
            finally
            {
                desalg.Clear();
                md5.Clear();
            }
            return Convert.ToBase64String(results);
        }
开发者ID:trquth,项目名称:greenhousebanner-Edit,代码行数:25,代码来源:MD5Helper.cs


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