2是不是可以这样:
string=使用单位名称+“*”+开始使用时间+“*”+天数;//这里用*做分割符号
然后对string加密
程序对string解密后判断开始使用时间、天数从而控制程序

解决方案 »

  1.   

    using System;
    using System.Text;
    using System.Security.Cryptography;namespace Sanxing.WebControls.Licensing.Unit
    {
        /// <summary>
        /// 使用DES进行对称加密处理的工具类。
        /// </summary>
        internal sealed class DesUnit
        {
            // 密码
            private const string sKey = "sD2#bA*)";        /// <summary>
            /// 进行DES加密。
            /// </summary>
            /// <param name="pToEncrypt">要加密的字符串。</param>
            /// <returns>以Base64格式返回的加密字符串。</returns>
            public static string Encrypt(string pToEncrypt)
            {
                using(DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
    byte[]  inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    using(CryptoStream cs = new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write))
    {
    cs.Write(inputByteArray,0,inputByteArray.Length);
    cs.FlushFinalBlock();
    cs.Close();
    }
    string str = Convert.ToBase64String(ms.ToArray());
    ms.Close();
    return str;
                }
            }

            /// <summary>
            /// 进行DES解密。
            /// </summary>
            /// <param name="pToDecrypt">要解密的以Base64</param>
            /// <returns>已解密的字符串。</returns>
            public static string Decrypt(string pToDecrypt)
            {
                byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
                using(DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
    des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
    des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    using(CryptoStream cs = new CryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write))
    {
    cs.Write(inputByteArray,0,inputByteArray.Length);
    cs.FlushFinalBlock();
    cs.Close();
    }
    string str = Encoding.UTF8.GetString(ms.ToArray());
    ms.Close();
    return str;
        }
            }
        }
    }
      

  2.   

    TO orbitbd
    MB是不中可逆的吧?TO int64,你的想法倒是和我一样,只是这个加密后如何变成一个"具有观赏性"的字母和数字组合,这个加密方法好像较难,而且因为单位名字长度会变,可是我希望这个序列号的长度是不变的,这是不是有点困难?
      

  3.   

    ToBitsBird,你的加密能减少文字长度吗(最好是变成一串数字,至少要有观赏性)?你能告诉我"宁波宁波中国中国上海海谢谢你的回复",加密后是什么吗?