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


C# SymmetricAlgorithm.GetType方法代码示例

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


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

示例1: EncryptionProvider

        /// <summary>
        /// Initializes a new instance of the EncryptionProvider class.
        /// </summary>
        /// <param name="algorithm">The symmetric algorithm to use during cryptographic transformations.</param>
        /// <param name="padding">The padding mode to use.</param>
        /// <param name="mode">The cipher mode to use.</param>
        /// <param name="key">The key to use.</param>
        /// <param name="iv">The initialization vector to use.</param>
        public EncryptionProvider(SymmetricAlgorithm algorithm, byte[] key, byte[] iv)
        {
            _algorithm = algorithm;
            //            _algorithm.Padding = PaddingMode.PKCS7;
            //            _algorithm.Mode = CipherMode.CBC;
            _algorithm.Key = key;
            _algorithm.IV = iv;

            foreach (KeySizes keySize in _algorithm.LegalKeySizes)
                Debug.WriteLine(string.Format("Algorithm: {0}, KeyMaxSize: {1}, KeyMinSize: {2}", _algorithm.GetType().Name, keySize.MaxSize, keySize.MinSize));
        }
开发者ID:FireBall1725,项目名称:Carbon.Framework,代码行数:19,代码来源:EncryptionProvider.cs

示例2: SecuritySession_KnownSymmetric

        /// <summary>
        /// Initializes an instance of the SecuritySession_KnownSymmetric class.
        /// </summary>
        /// <param name="symmetricAlgorithm">The symmetricAlgorithm to be used.</param>
        /// <param name="name">The name of the security context.</param>
        public SecuritySession_KnownSymmetric(SymmetricAlgorithm symmetricAlgorithm, string name)
            : base(name, null)
        {
            // LOG:
            BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;
            if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0 )
            {
                binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySession_KnownSymmetric.SecuritySession_KnownSymmetric",
                    LogMessageType.SecuritySessionKey, null, null, this.Remote, null,
                    GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, this,
                    name, -1,
                    0, 0, 0, "Encryption using " + symmetricAlgorithm.GetType().ToString(), null, null, null,
                    "Security Session security information is initialized.");
            }

            this.SymmetricAlgorithm = symmetricAlgorithm;
            this._encryptor = this.SymmetricAlgorithm.CreateEncryptor();
            this._decryptor = this.SymmetricAlgorithm.CreateDecryptor();
            this.IsEstablishedEvent.Set();
        }
开发者ID:ArsenShnurkov,项目名称:GenuineChannels,代码行数:25,代码来源:SecuritySession_KnownSymmetric.cs

示例3: GenerateKey

 private void GenerateKey(SymmetricAlgorithm alg)
 {
     alg.GenerateKey();
       alg.GenerateIV();
       Debug.WriteLine("Algorithm: " + alg.GetType().Name.PadRight(30) + " keySize(bits): " + alg.KeySize + " key: " + HexUtil.ByteArrayToHex(alg.Key));
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:6,代码来源:HashCryptTests.cs

示例4: Encrypt

        /// <summary>
        /// The encrypt.
        /// </summary>
        /// <param name="plainText">
        /// The plain text.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="iv">
        /// The iv.
        /// </param>
        /// <param name="desProvider">
        /// The des provider.
        /// </param>
        /// <returns>
        /// </returns>
        private static byte[] Encrypt(byte[] plainText, byte[] key, byte[] iv, SymmetricAlgorithm desProvider)
        {
            int appendLength = 8 - (plainText.Length % 8);
            appendLength = appendLength == 8 ? 0 : appendLength;
            if (appendLength != 0)
            {
                var newArray = new byte[plainText.Length + appendLength];
                Array.Copy(plainText, newArray, plainText.Length);
                plainText = newArray;
            }

            // ICryptoTransform cryptoTransform = desProvider.CreateEncryptor(desProvider.Key, desProvider.IV);

            // 密钥
            MethodInfo mi = desProvider.GetType().GetMethod(
                "_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance);
            object[] param = { key, CipherMode.ECB, iv, desProvider.FeedbackSize, 0 };
            var desEncrypt = (ICryptoTransform)mi.Invoke(desProvider, param);

            // var ms = new MemoryStream();
            // var myCryptoStream = new CryptoStream(ms, desEncrypt, CryptoStreamMode.Write);
            // myCryptoStream.Write(plainText, 0, plainText.Length);
            // /* 密文 */
            // return ms.ToArray();
            return desEncrypt.TransformFinalBlock(plainText, 0, plainText.Length);
        }
开发者ID:relaxar,项目名称:bin.net,代码行数:43,代码来源:DesCalculator.cs

示例5: Decrypt

        /// <summary>
        /// The decrypt.
        /// </summary>
        /// <param name="cipherText">
        /// The cipher text.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="iv">
        /// The iv.
        /// </param>
        /// <param name="desProvider">
        /// The des provider.
        /// </param>
        /// <returns>
        /// </returns>
        private static byte[] Decrypt(byte[] cipherText, byte[] key, byte[] iv, SymmetricAlgorithm desProvider)
        {
            /* DES解密 */

            // ICryptoTransform cryptoTransform = desProvider.CreateDecryptor(desProvider.Key, desProvider.IV);
            // 密钥
            MethodInfo mi = desProvider.GetType().GetMethod(
                "_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance);
            object[] param = { key, CipherMode.ECB, iv, desProvider.FeedbackSize, 1 };
            var desEncrypt = (ICryptoTransform)mi.Invoke(desProvider, param);

            // var ms = new MemoryStream();
            // var myCryptoStream = new CryptoStream(ms, desEncrypt, CryptoStreamMode.Write);
            // myCryptoStream.Write(cipherText, 0, cipherText.Length);
            // return ms.ToArray();
            return desEncrypt.TransformFinalBlock(cipherText, 0, cipherText.Length);
        }
开发者ID:relaxar,项目名称:bin.net,代码行数:34,代码来源:DesCalculator.cs

示例6: SymmetricCipherPair

 public SymmetricCipherPair(byte[] cipher, byte[] iv, SymmetricAlgorithm alg)
     : base(cipher, iv)
 {
     Condition.Requires(alg).IsNotNull();
     this.AlgorithmType = alg.GetType();
 }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:6,代码来源:SymmetricCipherPair.cs


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