本文整理汇总了C#中CipherMode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# CipherMode.ToString方法的具体用法?C# CipherMode.ToString怎么用?C# CipherMode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CipherMode
的用法示例。
在下文中一共展示了CipherMode.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DontDecryptLastBlock
// see bug #80439
public void DontDecryptLastBlock (CipherMode mode, PaddingMode padding)
{
SymmetricAlgorithm algo = Algorithm;
algo.Mode = mode;
algo.Padding = padding;
ICryptoTransform enc = algo.CreateEncryptor ();
byte[] plaintext = new byte[BlockSize * 7];
byte[] encdata = new byte[BlockSize * 8];
int len = enc.TransformBlock (plaintext, 0, plaintext.Length, encdata, 0);
Assert.AreEqual (plaintext.Length, len, "encdata");
ICryptoTransform dec = algo.CreateDecryptor ();
byte[] decdata = new byte[plaintext.Length];
len = dec.TransformBlock (encdata, 0, encdata.Length, decdata, 0);
Assert.AreEqual (plaintext.Length, len, "decdata");
Assert.AreEqual (plaintext, decdata, "TransformBlock." + mode.ToString ());
}
示例2: DontDecryptLastBlock_Final
// see bug #80439 (2nd try, reopened)
// same as DontDecryptLastBlock except
// a. the encryption transform was final (padding was added)
// b. we can call/test decryption TransformFinalBlock too
public void DontDecryptLastBlock_Final (CipherMode mode, PaddingMode padding)
{
SymmetricAlgorithm algo = Algorithm;
algo.Mode = mode;
algo.Padding = padding;
ICryptoTransform enc = algo.CreateEncryptor ();
byte[] plaintext = new byte[BlockSize * 7];
byte[] encdata = enc.TransformFinalBlock (plaintext, 0, plaintext.Length);
switch (padding) {
case PaddingMode.None:
case PaddingMode.Zeros:
Assert.AreEqual (BlockSize * 7, encdata.Length, "encdata");
break;
default:
Assert.AreEqual (BlockSize * 8, encdata.Length, "encdata");
break;
}
ICryptoTransform dec = algo.CreateDecryptor ();
byte[] decdata = new byte[plaintext.Length];
dec.TransformBlock (encdata, 0, encdata.Length, decdata, 0);
Assert.AreEqual (plaintext, decdata, "TransformBlock." + mode.ToString ());
dec = algo.CreateDecryptor ();
byte[] final = dec.TransformFinalBlock (encdata, 0, encdata.Length);
Assert.AreEqual (plaintext, final, "TransformFinalBlock." + mode.ToString ());
}
示例3: BlowFishTransform
public BlowFishTransform(byte[] key, byte[] iv, bool encrypt, bool isLittleEndian, CipherMode cipherMode, PaddingMode paddingMode)
{
switch (cipherMode)
{
case CipherMode.CBC:
case CipherMode.ECB:
break;
default:
throw new NotSupportedException($"CipherMode {cipherMode.ToString()} is not supported.");
}
this.PaddingMode = paddingMode;
this.IV = iv;
this.IsEncryptor = encrypt;
this.CipherMode = cipherMode;
this.IsLittleEndian = isLittleEndian;
this.CipherMode = CipherMode.ECB;
this.SetupKey(key);
}