制作一个简单的授权文件
以.licx 后缀的文本文件,在其中保存经过加密的授权码,然后通过简单的加/解密,和文件读写操作,就可以完成相应的授权验证。
licenses.licx
用记事本打开就有FreeTextBoxControls.FreeTextBox, FreeTextBox, Version=3.0.3300.3, Culture=neutral, PublicKeyToken=5962a4e684a48b87
看看加密,解密
public string DesEncrypt(string strText, string strEncrKey)
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,strEncrKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception error)
{
return "error: " +error.Message+ "/r ";
}
}
public string DesDecrypt(string strText,string sDecrKey)
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch(System.Exception error)
{
return "error: "+error.Message+ "/r ";
}
}
实例化一个类,变量名jiami
jiami.DesEncrypt( "www.mytopwin.com ");
得到wIToenOWESRztJZx42D9MSbLpu7HvK2H
解密
jiami.DesDecrypt( "wIToenOWESRztJZx42D9MSbLpu7HvK2H ");
的到www.mytopwin.com