当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 模拟信息加密流程图简介
| 模拟信息加密流程图简介 下载源代码 string fileName = OpenFile("请打开要解密的文件:");FileStream fs = new FileStream(fileName,FileMode.Open,FileAccess.Read); (int)fs.Length - 1152-144 运算结果就是中间密文---EncryptionDate 的长度。解密中间密文后,紧接着就要处理时间戳啦。我们分析时间戳的字节数组组成吧: 文件散列长度 :16接收时间 :23签名长度 :128总共长度 :167 既然知道这些字节数组的组成,你该知道怎么做了吧?关于处理接收时间戳的处理上,有点要注意的: public static byte [] GetTimeNow(){ //这样转化成的格式为:2004-11-09 13:04:28-108 23个字节 DateTime now = DateTime.Now; System.Text.UTF8Encoding utf = new System.Text.UTF8Encoding(); string month = null ; if(now.Month<10) month = "0"+now.Month.ToString(); else month = now.Month.ToString(); string day = null; if(now.Day<10) day = "0" + now.Day.ToString(); else day = now.Day.ToString(); string millisecond = null; if(now.Millisecond<10) millisecond = "00"+now.Millisecond.ToString(); if(now.Millisecond>=10&&now.Millisecond<=99) millisecond = "0" + now.Millisecond.ToString(); if(now.Millisecond>=100) millisecond = now.Millisecond.ToString(); string FullFormatTime = now.Year.ToString() + "-" + month + "-" + day + " " + now.ToLongTimeString() + "-" + millisecond ; //比如:2004-11-09 13:04:28-108 return utf.GetBytes( FullFormatTime ); } 这样处理后的结果是接收时间精确到毫秒,且固定字节长度为23个字节。我们把第一个流程图的结果写进文件中去(其路径与你要加密的原始明文在同一目录下,主要是为了储存的方便),而流程图二的解密结果则保存在bin\Release目下。这样解密时需要读取文件,这里提供了两种方法,第一种把文件内容读取到一个数组里面,另外一种是需要时直接从文件中提取的指定的字节数组。第一种方法把文件内容读取到一数组,解密时分解数组,使用Buffer.BlockCopy( )函数分解既可。比如,从fileContent数组中偏移量1152处开始复制“length”长度字节复制到一个新的数组“Encrypt_Two”中去。int length = (int)fs.Length-1296;// -1152-144 ; //密文的长度AllEncryptedDataEncrypt_Two = new byte[ length ];Buffer.BlockCopy(fileC |