本文整理汇总了C#中MonoTests.System.Security.Cryptography.DebugStream类的典型用法代码示例。如果您正苦于以下问题:C# DebugStream类的具体用法?C# DebugStream怎么用?C# DebugStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DebugStream类属于MonoTests.System.Security.Cryptography命名空间,在下文中一共展示了DebugStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write_OverflowCount
public void Write_OverflowCount ()
{
DebugStream debug = new DebugStream ();
byte[] buffer = new byte [8];
cs = new CryptoStream (debug, encryptor, CryptoStreamMode.Write);
cs.Write (buffer, 0, Int32.MaxValue);
}
示例2: PartialRoundtripRead
public void PartialRoundtripRead ()
{
byte[] encrypted;
using (DebugStream mem1 = new DebugStream ()) {
byte[] toEncrypt = Encoding.Unicode.GetBytes ("Please encode me!");
using (CryptoStream crypt = new CryptoStream (mem1, aes.CreateEncryptor (), CryptoStreamMode.Write)) {
crypt.Write (toEncrypt, 0, toEncrypt.Length);
crypt.FlushFinalBlock ();
}
encrypted = mem1.ToArray ();
}
using (DebugStream mem2 = new DebugStream (encrypted)) {
byte[] buffer = new byte [1024];
CryptoStream cr = new CryptoStream (mem2, aes.CreateDecryptor (), CryptoStreamMode.Read);
int len = cr.Read (buffer, 0, 20);
cr.Clear ();
cr.Close ();
Assert.AreEqual (20, len, "Partial Length Read");
Assert.AreEqual ("Please enc", Encoding.Unicode.GetString (buffer, 0, len), "Partial Block Read");
}
}
示例3: SetLength
public void SetLength ()
{
DebugStream debug = new DebugStream ();
cs = new CryptoStream (debug, encryptor, CryptoStreamMode.Read);
cs.SetLength (0);
}
示例4: Write_InvalidOffset
public void Write_InvalidOffset ()
{
DebugStream debug = new DebugStream ();
byte[] buffer = new byte [8];
cs = new CryptoStream (debug, encryptor, CryptoStreamMode.Write);
cs.Write (buffer, 5, 4);
}
示例5: FromBase64_Write
public void FromBase64_Write ()
{
string expected = "http://www.go-mono.com/";
byte[] data = Encoding.UTF8.GetBytes (expected);
string temp = Convert.ToBase64String (data, 0, data.Length);
data = Encoding.UTF8.GetBytes (temp);
DebugStream debug = new DebugStream ();
ICryptoTransform base64 = new FromBase64Transform ();
cs = new CryptoStream (debug, base64, CryptoStreamMode.Write);
cs.Write (data, 0, data.Length);
cs.FlushFinalBlock ();
byte[] encoded = debug.ToArray ();
string result = Encoding.UTF8.GetString (encoded);
Assert.AreEqual (expected, result, "FromBase64_Write");
}
示例6: Seek
public void Seek ()
{
DebugStream debug = new DebugStream ();
cs = new CryptoStream (debug, encryptor, CryptoStreamMode.Read);
cs.Seek (0, SeekOrigin.Begin);
}
示例7: DecryptorWriteBlocks
public void DecryptorWriteBlocks ()
{
DebugStream debug = new DebugStream ();
byte[] key = {0, 1, 2, 3, 4, 5, 6, 7};
byte[] iv = {0, 1, 2, 3, 4, 5, 6, 7};
DES des = DES.Create ();
CryptoStream csd = new CryptoStream (debug, des.CreateDecryptor (key, iv), CryptoStreamMode.Write);
byte[] data = new byte [64] { 0xE1, 0xB2, 0x46, 0xE5, 0xA7, 0xC7, 0x4C, 0xBC, 0xD5, 0xF0, 0x8E, 0x25, 0x3B, 0xFA, 0x23, 0x80, 0x03, 0x16, 0x18, 0x17, 0xA3, 0x59, 0xBA, 0xAC, 0xFC, 0x47, 0x57, 0x2A, 0xF9, 0x44, 0x07, 0x84, 0x20, 0x74, 0x06, 0x38, 0xC2, 0xF3, 0xA1, 0xCE, 0x8C, 0x73, 0xB1, 0xE3, 0x75, 0x03, 0x66, 0x89, 0xF0, 0x4E, 0x98, 0x68, 0xB1, 0xBD, 0x85, 0x25, 0xFF, 0x4B, 0x11, 0x74, 0xEF, 0x14, 0xC8, 0xE9 };
csd.Write (data, 0, 64);
Assert.AreEqual (56, debug.Length, "Length");
// last block is kept for later processing
}
示例8: DecryptPartial_TransformFinalBlock_2Pass
public void DecryptPartial_TransformFinalBlock_2Pass ()
{
byte[] key = {0, 1, 2, 3, 4, 5, 6, 7};
byte[] iv = {0, 1, 2, 3, 4, 5, 6, 7};
DES des = DES.Create ();
byte[] data = Encoding.Unicode.GetBytes ("ximian"); // 12 bytes, 1.5 DES block size
DebugStream encrypted = new DebugStream ();
cs = new CryptoStream (encrypted, des.CreateEncryptor (key, iv), CryptoStreamMode.Write);
cs.Write (data, 0, data.Length);
cs.Close ();
data = encrypted.ToArray ();
DebugStream decrypted = new DebugStream (data);
cs = new CryptoStream (decrypted, des.CreateDecryptor (key, iv), CryptoStreamMode.Read);
int len = cs.Read (data, 0, 6);
Assert.AreEqual (6, len, "Length (1st pass)");
Assert.AreEqual ("xim", Encoding.Unicode.GetString (data, 0, len), "Partial DES Roundtrip");
len += cs.Read (data, 6, 8);
Assert.AreEqual (12, len, "Length (1st+2nd)");
Assert.AreEqual ("ximian", Encoding.Unicode.GetString (data, 0, len), "Full DES Roundtrip");
cs.Close ();
}
示例9: CascadedCryptoStream_Read
public void CascadedCryptoStream_Read ()
{
byte[] encdata = new byte[] { 0x8C, 0x24, 0x76, 0x74, 0x09, 0x79, 0x2B, 0xD3, 0x47, 0xC3, 0x32, 0xF5, 0xF3, 0x1A, 0x5E, 0x57, 0x04, 0x33, 0x2E, 0xB8, 0x50, 0x77, 0xB2, 0xA1 };
DebugStream debug = new DebugStream (encdata);
// decrypt data and validate its hash in one Read operation
byte[] key = {0, 1, 2, 3, 4, 5, 6, 7};
byte[] iv = {0, 1, 2, 3, 4, 5, 6, 7};
DES des = DES.Create ();
CryptoStream csd = new CryptoStream (debug, des.CreateDecryptor (key, iv), CryptoStreamMode.Read);
MD5 hash = MD5.Create ();
CryptoStream csh = new CryptoStream (csd, hash, CryptoStreamMode.Read);
byte[] data = new byte [1024];
int length = csh.Read (data, 0, data.Length);
csh.Close ();
string result = Encoding.UTF8.GetString (data, 0, length);
Assert.AreEqual ("http://www.go-mono.com/", result, "Decrypted");
byte[] digest = hash.Hash;
Assert.AreEqual ("71-04-12-D1-95-01-CF-F9-8D-8F-F8-0D-F9-AA-11-7D", BitConverter.ToString (digest), "Hash Validation");
}
示例10: EncryptorWriteBlocks
public void EncryptorWriteBlocks ()
{
DebugStream debug = new DebugStream ();
byte[] key = {0, 1, 2, 3, 4, 5, 6, 7};
byte[] iv = {0, 1, 2, 3, 4, 5, 6, 7};
DES des = DES.Create ();
CryptoStream cse = new CryptoStream (debug, des.CreateEncryptor (key, iv), CryptoStreamMode.Write);
byte[] data = new byte [64];
cse.Write (data, 0, 64);
Assert.AreEqual (64, debug.Length, "Length");
cse.Close ();
}
示例11: CascadedCryptoStream_Write
public void CascadedCryptoStream_Write ()
{
DebugStream debug = new DebugStream ();
// calculate both the hash (before encryption) and encrypt in one Write operation
byte[] key = {0, 1, 2, 3, 4, 5, 6, 7};
byte[] iv = {0, 1, 2, 3, 4, 5, 6, 7};
DES des = DES.Create ();
CryptoStream cse = new CryptoStream (debug, des.CreateEncryptor (key, iv), CryptoStreamMode.Write);
MD5 hash = MD5.Create ();
CryptoStream csh = new CryptoStream (cse, hash, CryptoStreamMode.Write);
byte[] data = Encoding.UTF8.GetBytes ("http://www.go-mono.com/");
csh.Write (data, 0, data.Length);
csh.FlushFinalBlock ();
byte[] result = debug.ToArray ();
Assert.AreEqual ("8C-24-76-74-09-79-2B-D3-47-C3-32-F5-F3-1A-5E-57-04-33-2E-B8-50-77-B2-A1", BitConverter.ToString (result), "Encrypted");
byte[] digest = hash.Hash;
Assert.AreEqual ("71-04-12-D1-95-01-CF-F9-8D-8F-F8-0D-F9-AA-11-7D", BitConverter.ToString (digest), "Hash");
}
示例12: ToBase64_Read
public void ToBase64_Read ()
{
byte[] original = Encoding.UTF8.GetBytes ("http://www.go-mono.com/");
DebugStream debug = new DebugStream (original);
ICryptoTransform base64 = new ToBase64Transform ();
cs = new CryptoStream (debug, base64, CryptoStreamMode.Read);
byte[] data = new byte [1024];
int length = cs.Read (data, 0, data.Length);
cs.Close ();
string result = Encoding.UTF8.GetString (data, 0, length);
Assert.AreEqual ("aHR0cDovL3d3dy5nby1tb25vLmNvbS8=", result, "ToBase64_Read");
}
示例13: ToBase64_Write
public void ToBase64_Write ()
{
byte[] data = Encoding.UTF8.GetBytes ("http://www.go-mono.com/");
DebugStream debug = new DebugStream ();
ICryptoTransform base64 = new ToBase64Transform ();
cs = new CryptoStream (debug, base64, CryptoStreamMode.Write);
cs.Write (data, 0, data.Length);
cs.FlushFinalBlock ();
byte[] encoded = debug.ToArray ();
string result = Encoding.UTF8.GetString (encoded);
Assert.AreEqual ("aHR0cDovL3d3dy5nby1tb25vLmNvbS8=", result, "ToBase64_Write");
}
示例14: NonMultipleOfBlockSize_Encrypt
// Adapted from Subba Rao Thirumoorthy email on mono-devel-list (december 2003)
private byte[] NonMultipleOfBlockSize_Encrypt (ICryptoTransform ct, byte[] data)
{
DebugStream stream = new DebugStream ();
CryptoStream CryptStream = new CryptoStream (stream, ct, CryptoStreamMode.Write);
int len = 0;
long myLength = 0;
byte[] Buffer = new byte [1024];
DebugStream fout = new DebugStream (data);
while (myLength < data.Length) {
len = fout.Read (Buffer, 0, 1023);
if (len == 0)
break;
CryptStream.Write (Buffer, 0, len);
CryptStream.Flush ();
myLength = myLength + len;
}
CryptStream.FlushFinalBlock ();
// we must ensure that the result is correct
Assert.AreEqual (64, len, "Length(final)");
byte[] result = stream.ToArray ();
string end = BitConverter.ToString (result, 65520, 16);
Assert.AreEqual ("04-70-19-1D-28-C5-BD-9A-23-C6-60-E2-28-96-38-65", end, "End part");
CryptStream.Close();
stream.Close();
return result;
}
示例15: GetLength
public void GetLength ()
{
DebugStream debug = new DebugStream ();
cs = new CryptoStream (debug, encryptor, CryptoStreamMode.Read);
long x = cs.Length;
}