要求下面这个过程的相反函数,即输入一个结果(如:celerySingleLicense)就能得到下面这个函数的输入
using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;
private string DecryptLicenseData(string input)
{
byte[] encryptionKeyBytes = new byte[] { 0x39, 0x48, 0x42, 50, 0x38, 0x31, 70, 0x36 }
DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider();
ICryptoTransform transform1 = provider1.CreateDecryptor(encryptionKeyBytes, encryptionKeyBytes); //创建解密对象
MemoryStream stream1 = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream1, transform1, CryptoStreamMode.Write); //将数据流链接到加密转换流
byte[] buffer1 = new byte[input.Length]; //输入字符转换为byte数组
try
{
buffer1 = Convert.FromBase64CharArray(input.ToCharArray(), 0, input.Length);
}
catch (Exception)
{
return "Error. Input Data is not base64 encoded.";
}
long num1 = 0;
long num2 = input.Length;
try
{
while (num2 >= num1)
{
stream2.Write(buffer1, 0, buffer1.Length);
num1 = stream1.Length + Convert.ToUInt32((int) ((buffer1.Length / provider1.BlockSize) * provider1.BlockSize));
}
string text1 = new ASCIIEncoding().GetString(stream1.GetBuffer(), 0, (int) stream1.Length);
string text2 = text1.Substring(0, 5);
int num3 = Convert.ToInt32(text2);
return text1.Substring(5, num3);
}
catch (Exception)
{
return "";
}
}

解决方案 »

  1.   

    加密方法
    ///input                为  加密内容
    ///encryptionKeyBytes   为  加密KEy public string Encrypt()
    {
    string strResult = "";
    string input = "zhaoyingqi";
    input = String.Format("{0,5:00000}"+input, input.Length);
    byte[] encryptionKeyBytes = new byte[] { 0x39, 0x48, 0x42, 50, 0x38, 0x31, 70, 0x36 };
    byte[] rbData = Encoding.Default.GetBytes(input);
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    ICryptoTransform desEncrypt = des.CreateEncryptor(encryptionKeyBytes,encryptionKeyBytes);
    MemoryStream mStream = new MemoryStream(rbData); 
    CryptoStream cs = new CryptoStream(mStream, desEncrypt, CryptoStreamMode.Read);        
    MemoryStream mOut = new MemoryStream();
    int bytesRead; 
    byte[] output = new byte[1024]; 
    do 

    bytesRead = cs.Read(output,0,1024);
    if (bytesRead != 0) 
    mOut.Write(output,0,bytesRead); 
    } while (bytesRead > 0); 
    if (mOut.Length == 0)       
    strResult = "";
    else
    strResult = Convert.ToBase64String(mOut.GetBuffer(), 0, (int)mOut.Length);
    return strResult;
    }