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


C# ICryptoTransform.Dispose方法代码示例

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


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

示例1: EncryptDecryptAndDispose

        private static void EncryptDecryptAndDispose(ICryptoTransform crypto, ICryptoTransform decrypto, byte[] data)
        {
            var encryptedData = crypto.TransformFinalBlock(data, 0, data.Length);
            var decryptedData = decrypto.TransformFinalBlock(encryptedData, 0, encryptedData.Length);

            // NOTE: no need to check if they are equal
            //if (!decryptedData.AllEqual(data))
               // throw new InvalidProgramException();

            crypto.Dispose();
            decrypto.Dispose();
        }
开发者ID:aliostad,项目名称:EncryptionBenchmark,代码行数:12,代码来源:Program.cs

示例2: Process

            /// <summary>
            /// Process the data with CryptoStream
            /// </summary>
            protected byte[] Process(byte[] data, int startIndex, int count, ICryptoTransform cryptor)
            {
                //
                // the memory stream granularity must match the block size
                // of the current cryptographic operation
                //
                int capacity = count;
                int mod = count % algorithm.BlockSize;
                if (mod > 0)
                {
                    capacity += (algorithm.BlockSize - mod);
                }

                MemoryStream memoryStream = new MemoryStream(capacity);

                CryptoStream cryptoStream = new CryptoStream(
                    memoryStream,
                    cryptor,
                    CryptoStreamMode.Write);

                cryptoStream.Write(data, startIndex, count);
                cryptoStream.FlushFinalBlock();

                cryptoStream.Close();
                cryptoStream = null;

                cryptor.Dispose();
                cryptor = null;

                return memoryStream.ToArray();
            }
开发者ID:ECain,项目名称:MissionPlanner,代码行数:34,代码来源:Crypto.cs

示例3: ReturnCryptoTransform

 private static void ReturnCryptoTransform(bool fEncrypt, ICryptoTransform ct, bool useValidationSymAlgo, bool legacyMode)
 {
     ct.Dispose();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:MachineKeySection.cs

示例4: DecryptRecord

        public void DecryptRecord(byte[] fragment, out byte[] dcrFragment, out byte[] dcrMAC)
        {
            int fragmentSize = 0;
            int paddingLength = 0;

            // Decrypt message fragment ( fragment + mac [+ padding + padding_length] )

            DecryptionTransform = DecryptionAlgorithm.CreateDecryptor(ServerWriteKey, LastCipherTextBlock);
            byte [] bOutput = this.DecryptionTransform.TransformFinalBlock(fragment, 0, fragment.Length);
            DecryptionTransform.Dispose();

            //this.DecryptionTransform.TransformBlock(fragment, 0, fragment.Length, bOutput, 0);

            if (bOutput.Length != fragment.Length)
            {
                /// It appears the above may remove all the padding, but lease the padding length byte on
                ///
                dcrFragment = new byte[bOutput.Length - this.SecurityParameters.Cipher.HashSize-1];
                dcrMAC = new byte[this.SecurityParameters.Cipher.HashSize];

                Array.Copy(bOutput, 0, dcrFragment, 0, dcrFragment.Length);
                Array.Copy(bOutput, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length);
                return;
            }

            fragment = bOutput;

            // optimization: decrypt "in place", worst case: padding will reduce the size of the data
            // this will cut in half the memory allocations (dcrFragment and dcrMAC remains)

            // Calculate fragment size
            // Calculate padding_length
            paddingLength = fragment[fragment.Length - 1];

            ///// Not sure what's going on, but the Server Finished handshake message has it's padding byte set to 0, and there are 11 bytes filled with 0s,
            ///// I can't find documentation on why, so have to assume it's a bug in openssl... see if we can work around it
            /////
            //if (paddingLength == 0)
            //    paddingLength = 11;

            if (paddingLength > fragment.Length)
                throw new Exception("Decryption Failed, padding length is longer than the fragment length");

            fragmentSize = (fragment.Length - (paddingLength + 1)) - this.SecurityParameters.Cipher.HashSize;

            dcrFragment = new byte[fragmentSize];
            dcrMAC = new byte[this.SecurityParameters.Cipher.HashSize];

            Array.Copy(fragment, 0, dcrFragment, 0, dcrFragment.Length);
            Array.Copy(fragment, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length);
        }
开发者ID:Hitchhikrr,项目名称:Voip,代码行数:51,代码来源:TLSStructures.cs


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