本文整理汇总了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();
}
示例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();
}
示例3: ReturnCryptoTransform
private static void ReturnCryptoTransform(bool fEncrypt, ICryptoTransform ct, bool useValidationSymAlgo, bool legacyMode)
{
ct.Dispose();
}
示例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);
}