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


C# SymmetricAlgorithm.CreateEncryptor方法代码示例

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


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

示例1: EncryptString

        public static string EncryptString(string Value, string parKey)
        {
            mCSP = SetEnc();
            string iv = "PenS8UCVF7s=";
            mCSP.IV = Convert.FromBase64String(iv);
            string key = SetLengthString(parKey.ToString(), 32);
            mCSP.Key = Convert.FromBase64String(key);
            ICryptoTransform ct;
            MemoryStream ms;
            CryptoStream cs;
            Byte[] byt = new byte[64];

            try
            {
                ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV);
                byt = Encoding.UTF8.GetBytes(Value);
                ms = new MemoryStream();
                cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
                cs.Write(byt, 0, byt.Length);
                cs.FlushFinalBlock();
                cs.Close();

                return Convert.ToBase64String(ms.ToArray());
            }
            catch (Exception Ex)
            {
                throw (new Exception("An error occurred while encrypting string"));
            }
        }
开发者ID:danygolden,项目名称:gianfratti,代码行数:29,代码来源:Crypto.cs

示例2: EncryptFile

		/// <summary>
		/// 加密文件
		/// </summary>
		/// <param name="inName">来源文件</param>
		/// <param name="outName">输出文件</param>
		/// <param name="Algorithm">对称算法</param>
		public static void EncryptFile(string inName, string outName, SymmetricAlgorithm Algorithm)
		{
			FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
			using (FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write))
			{
				fout.SetLength(0);

				CryptoStream encStream = new CryptoStream(fout, Algorithm.CreateEncryptor(), CryptoStreamMode.Write);

				//Read from the input file, then encrypt and write to the output file.
				//Create variables to help with read and write.
				long rdlen = 0;					//This is the total number of bytes written.
				int len;						//This is the number of bytes to be written at a time.
				byte[] bin = new byte[FileReadStep];
				while (rdlen < fin.Length)
				{
					len = fin.Read(bin, 0, FileReadStep);
					encStream.Write(bin, 0, len);
					rdlen += len;
				}

				encStream.Close();
				fin.Close();
			}
		}
开发者ID:lujinlong,项目名称:Apq,代码行数:31,代码来源:SymmetricAlgorithmHelper.cs

示例3: Encrypt

        public static byte[] Encrypt(string strText, SymmetricAlgorithm key)
        {
            // Create a memory stream.
            MemoryStream ms = new MemoryStream();

            // Create a CryptoStream using the memory stream and the
            // CSP(cryptoserviceprovider) DES key.
            CryptoStream crypstream = new CryptoStream(ms, key.CreateEncryptor(), CryptoStreamMode.Write);

            // Create a StreamWriter to write a string to the stream.
            StreamWriter sw = new StreamWriter(crypstream);

            // Write the strText to the stream.
            sw.WriteLine(strText);

            // Close the StreamWriter and CryptoStream.
            sw.Close();
            crypstream.Close();

            // Get an array of bytes that represents the memory stream.
            byte[] buffer = ms.ToArray();

            // Close the memory stream.
            ms.Close();

            // Return the encrypted byte array.
            return buffer;
        }
开发者ID:ctsxamarintraining,项目名称:cts451785,代码行数:28,代码来源:SymmetricKeyEncryption.cs

示例4: EncryptBytes

        public static byte[] EncryptBytes(SymmetricAlgorithm symAlg, byte[] inBlock)
        {
            ICryptoTransform xfrm = symAlg.CreateEncryptor();
            byte[] outBlock = xfrm.TransformFinalBlock(inBlock, 0, inBlock.Length);

            return outBlock;
        }
开发者ID:TheNaked,项目名称:Firewind,代码行数:7,代码来源:Encryption.cs

示例5: CipherTextStealingMode

        /// <summary>
        /// Initialize CipherTextStealingMode with a specific symmetric algorithm
        /// </summary>
        /// <param name="symmetricAlgorithm">The symmetric algorithm</param>
        public CipherTextStealingMode(SymmetricAlgorithm symmetricAlgorithm)
        {
            // in CTS Mode there is no padding
            symmetricAlgorithm.Padding = PaddingMode.None;

            // set the symmetric algorithm's mode to ECB
            // (for single block encryption and decryption)
            symmetricAlgorithm.Mode = CipherMode.ECB;

            // get the symmetric algorithm's block size in bytes
            blockSize = symmetricAlgorithm.BlockSize / 8;
            if (blockSize != symmetricAlgorithm.IV.Length)
            {
                throw new ArgumentException(
                    "The IV size should equal to the block size.");
            }

            // initialize local IV
            iv = symmetricAlgorithm.IV;

            // initialize cipher state using the symmetric algorithms's IV
            cipherState = new byte[blockSize];
            symmetricAlgorithm.IV.CopyTo(cipherState, 0);

            // create encryptor and decryptor
            encryptor = symmetricAlgorithm.CreateEncryptor();
            decryptor = symmetricAlgorithm.CreateDecryptor();
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:32,代码来源:CipherTextStealingMode.cs

示例6: EncryptEnvelopeKeyUsingSymmetricKey

 private static byte[] EncryptEnvelopeKeyUsingSymmetricKey(SymmetricAlgorithm symmetricAlgorithm, byte[] envelopeKey)
 {
     symmetricAlgorithm.Mode = CipherMode.ECB;
     using (ICryptoTransform encryptor = symmetricAlgorithm.CreateEncryptor())
     {
         return (encryptor.TransformFinalBlock(envelopeKey, 0, envelopeKey.Length));
     }
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:8,代码来源:EncryptionUtils.cs

示例7: Encrypt

		private byte[] Encrypt (SymmetricAlgorithm algo, PaddingMode padding, byte[] data) 
		{
			algo.IV = new byte [algo.BlockSize >> 3];
			algo.Mode = CipherMode.CBC;
			algo.Padding = padding;
			ICryptoTransform ct = algo.CreateEncryptor ();
			return ct.TransformFinalBlock (data, 0, data.Length);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:PaddingModeTest.cs

示例8: TransformByCryptoStream

        private byte[] TransformByCryptoStream(SymmetricAlgorithm algorithm, byte[] bytes, bool encrypt)
        {
            algorithm.Clear();

              if (encrypt)
            return TransformByCryptoStream(algorithm.CreateEncryptor(), bytes);
              else
            return TransformByCryptoStream(algorithm.CreateDecryptor(), bytes);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:9,代码来源:ICryptoTransformExtensions.cs

示例9: CreateCryptoTransform

        private static ICryptoTransform CreateCryptoTransform(SymmetricAlgorithm algorithm, CryptoAction action)
        {
            byte[] key = Encoding.ASCII.GetBytes(stringKey);
            byte[] vector = Encoding.ASCII.GetBytes(stringVector);

            return action == CryptoAction.Encrypt
                ? algorithm.CreateEncryptor(key, vector)
                : algorithm.CreateDecryptor(key, vector);
        }
开发者ID:xpss,项目名称:remote,代码行数:9,代码来源:CryptoHelper.cs

示例10: WinzipAesCryptoStream

        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
        {
            this.stream = stream;
            totalBytesLeftToRead = length;

            cipher = CreateCipher(winzipAesEncryptionData);

            var iv = new byte[BLOCK_SIZE_IN_BYTES];
            transform = cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv);
        }
开发者ID:yaozd,项目名称:sharpcompress,代码行数:10,代码来源:WinzipAesCryptoStream.cs

示例11: Encrypt

 public static byte[] Encrypt(SymmetricAlgorithm algorithm,byte[] data)
 {
     using (MemoryStream memory = new MemoryStream())
     {
         using (CryptoStream encrypt = new CryptoStream(memory, algorithm.CreateEncryptor(algorithm.Key, algorithm.IV), CryptoStreamMode.Write))
         {
             encrypt.Write(data, 0, data.Length);
         }
         return memory.ToArray();
     }
 }
开发者ID:node-net,项目名称:Node.Net,代码行数:11,代码来源:SymmetricAlgorithm.Extension.cs

示例12: EncryptPassword

        /// <summary>
        ///  Encrypts the offline transaction file using the TripleDES cryptography.
        /// </summary>
        /// <param name="Password"></param>
        /// <returns></returns>
        public static string EncryptPassword(string Password)
        {
            string testPwd = string.Empty;

            DES = new TripleDESCryptoServiceProvider();
            byte[] plaintext = Encoding.ASCII.GetBytes(Password);
            DES.Key = ParseKey(desKey);
            DES.IV = GetIV();
            //string decPwd = DecryptPassword("Lw5AEvoSG+7VlrMK+XgmGw==");
            byte[] encrypted = DES.CreateEncryptor().TransformFinalBlock(plaintext, 0, plaintext.Length);
            return Convert.ToBase64String(encrypted);
        }
开发者ID:nitinkhannas,项目名称:TCESS.ESales,代码行数:17,代码来源:EncryptDecrypt.cs

示例13: Encrypt

 private static byte[] Encrypt(string PlainText, SymmetricAlgorithm key)
 {
     MemoryStream ms = new MemoryStream();
     CryptoStream encStream = new CryptoStream(ms, key.CreateEncryptor(), CryptoStreamMode.Write);
     StreamWriter sw = new StreamWriter(encStream);
     sw.WriteLine(PlainText);
     sw.Close();
     encStream.Close();
     byte[] buffer = ms.ToArray();
     ms.Close();
     return buffer;
 }
开发者ID:manasheep,项目名称:Core3,代码行数:12,代码来源:Classes.cs

示例14: Encrypt

 public static byte[] Encrypt(SymmetricAlgorithm algorithm, byte[] src)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         using (CryptoStream cs = new CryptoStream(ms, algorithm.CreateEncryptor(), CryptoStreamMode.Write))
         {
             cs.Write(src, 0, src.Length);
             cs.FlushFinalBlock();
             return ms.ToArray();
         }
     }
 }
开发者ID:mashiro,项目名称:tig-feed-reader,代码行数:12,代码来源:CryptUtility.cs

示例15: CtrModeCryptoTransform

        public CtrModeCryptoTransform(SymmetricAlgorithm algorithm)
        {
            Contract.Requires(algorithm != null);

            algorithm.Mode = CipherMode.ECB;
            algorithm.Padding = PaddingMode.None;

            _algorithm = algorithm;
            _transform = algorithm.CreateEncryptor();
            _iv = algorithm.IV;
            _block = new byte[algorithm.BlockSize >> 3];
        }
开发者ID:jinhang2008,项目名称:FxSsh,代码行数:12,代码来源:CtrModeCryptoTransform.cs


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