本文整理汇总了C#中PaddingMode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PaddingMode.ToString方法的具体用法?C# PaddingMode.ToString怎么用?C# PaddingMode.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PaddingMode
的用法示例。
在下文中一共展示了PaddingMode.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PaddingTest
public static bool PaddingTest(Aes aes, PaddingMode mode, int offset, byte[] expected)
{
if (!CompareBytes(GetPaddingBytes(aes, mode, offset), expected))
{
Console.WriteLine("Error - padding failure");
Console.WriteLine("Algorithm: {0}", aes.ToString());
Console.WriteLine("Padding Mode: {0}", mode.ToString());
Console.WriteLine("Block Size: {0}", BlockSizeBytes + offset);
return false;
}
return true;
}
示例2: WriteByte
private void WriteByte (PaddingMode mode, bool padded)
{
byte[] Key = new byte[16];
byte[] IV = new byte[16];
byte[] Buffer = new byte[64];
Rijndael alg = Rijndael.Create ();
alg.Mode = CipherMode.CBC;
alg.Padding = mode;
MemoryStream cms = new MemoryStream ();
ICryptoTransform ct = alg.CreateEncryptor (Key, IV);
CryptoStream cs = new CryptoStream (cms, ct, CryptoStreamMode.Write);
for (int i = 0; i < Buffer.Length; i++)
cs.WriteByte (Buffer[i]);
cs.Close ();
byte[] result = cms.ToArray ();
// if padded then add one block, if not then it's the original length
int len = padded ? 80: 64;
Assert.AreEqual (len, result.Length, mode.ToString () + ".Encrypted.Length");
cms = new MemoryStream ();
ct = alg.CreateDecryptor (Key, IV);
cs = new CryptoStream (cms, ct, CryptoStreamMode.Write);
for (int i = 0; i < result.Length; i++)
cs.WriteByte (result[i]);
cs.Close ();
byte[] plaintext = cms.ToArray ();
Assert.AreEqual (64, plaintext.Length, mode.ToString () + ".Decrypted.Length");
Assert.AreEqual (Buffer, plaintext, mode.ToString () + ".Date");
}