刚学C#,这个例子是对一个字节加密, 首次运行时,realen=8,totallen=1,不明白为什么运行下面的循环while (readlen < totallen),下面语句的功能看不懂,readlen = (readlen + ((len / des.BlockSize) * des.BlockSize));Blocksizer查MSDN得知是数据块,是待加密的数据还是别的什么数据,请大虾指教。最好详细的给我讲一下这个例子。
------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace P__130
{
class Program
{
static void Main(string[] args)
{
MemoryStream memstr = new MemoryStream();
memstr.WriteByte((byte)1);
memstr.Position = 0;
FileStream desfile = new FileStream("Test1.cs",FileMode.OpenOrCreate,FileAccess.Write);
desfile.SetLength(0);
SymmetricAlgorithm des = SymmetricAlgorithm.Create();
byte[] bin = new byte[4096];
long readlen = 8;
long totallen = (long)memstr.Length;
int len;
CryptoStream encStream = new CryptoStream(desfile,des.CreateEncryptor(),CryptoStreamMode.Write);
Console.WriteLine("正在加密");
while (readlen < totallen)
{
len = memstr.Read(bin, 0, 4096);
encStream.Write(bin, 0, len);
readlen = (readlen + ((len / des.BlockSize) * des.BlockSize));
}
encStream.Close();
}
}
}