其中C盘的序列号,需要自己获取,十六进制转换成十进制的
private void jiemi() { string textnum, textsn, textend, textword; textword = textBox2.Text.ToString();//获取需要解密的字符串 textnum = textBox1.Text.ToString();//获取需要C盘序列号 textsn = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(textnum))).Replace("-", "").ToLower();//把C盘序列号进行转换 textend = textsn.Substring((Convert.ToInt16(textsn.Substring((textsn.Length – 2) – 3, 2), 0×10) % 4) * 6, 8);//密钥的获取前的处理 byte[] buffer1 = null; byte[] buffer2 = new byte[] { 0×36, 0×65, 0×27, 0×68, 0×19, 0×97, 0×11, 0×61 }; byte[] buffer3 = new byte[textword.Length]; MemoryStream stream1 = new MemoryStream(); buffer1 = Encoding.UTF8.GetBytes(textend.Substring(0, 8));//生成密钥 DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider(); buffer3 = Convert.FromBase64String(textword); CryptoStream stream2 = new CryptoStream(stream1, provider1.CreateDecryptor(buffer1, buffer2), CryptoStreamMode.Write);//进行DES解密 stream2.Write(buffer3, 0, buffer3.Length); stream2.FlushFinalBlock(); Encoding encoding1 = new UTF8Encoding(); textBox3.Text = encoding1.GetString(stream1.ToArray());//输出解密结果 }