用MD5算法或hash算法等做摘要算法试试。

解决方案 »

  1.   

    colinfly(Colin)的分析太对了,牛!
      

  2.   

    static String Convert(String str) {
    MD5 md5 = MD5.Create();
    byte[] bytes = md5.ComputeHash(Encoding.Unicode.GetBytes(str));
    return Encoding.Unicode.GetString(bytes);
    }
    注意编码,其它的编码也可以。
      

  3.   

    System.Security.Cryptography.HashAlgorithm 下面的哈希算法,这是比较号的解决方案。
      

  4.   

    TO:Montaque(侯永锋 [MVP])  
    System.Security.Cryptography.HashAlgorithm
    我去看看
      

  5.   

    private string getCountStr(string str,int count)
    {
    byte [] bwrite=Encoding.GetEncoding("GB2312").GetBytes(str.ToCharArray());
    if(bwrite.Length>=count)
    return Encoding.Default.GetString( bwrite,0,count);
    else return Encoding.Default.GetString(bwrite);
    }
    上面的这个方法就可以获得一个字符串中相应的字节数的子串。比如:
    str1="这真的是一个好人吗?" ;
    str2="abcdefghijklmnopqrs";
    分别调用上述函数,
    str1=getCountStr(str1,16);
    str2=getCountStr(str2,16);
    就会返回
    str1的值为 "这真的是一个好人"
    str2的值为 "abcdefghijklmnop"不过我做这里用的时英文操作系统,用的时候绝对没有问题,就是16个字节的.
    没试过在别的系统下,如果有必要的话,你调整一下getCountStr中的编码方式
    老大,写的够详细了吧。呵呵,快结帖给分吧
      

  6.   

    byte[] txt1 = System.Text.ASCIIEncoding.ASCII.GetBytes(textData.Text);
    byte[] key = System.Text.ASCIIEncoding.ASCII.GetBytes(textKey.Text);
    //’声明加密类,既使用何种加密方法
    System.Security.Cryptography.HMACSHA1 hma = new System.Security.Cryptography.HMACSHA1(key);
    //进行加密转换
    System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(System.IO.Stream.Null, hma, System.Security.Cryptography.CryptoStreamMode.Write); //将加密后的数据保存在TXT1这个变量中
    //’此时的txt1已经不是先前的要加密的文字,而是被刷新后的已经加密的数据。
    cStream.Write(txt1, 0 , txt1.Length);
    cStream.Close();
    //’显示加密的文字。
    textCryptography.Text = System.Text.ASCIIEncoding.ASCII.GetString(hma.Hash);如果要变成16字节的就没有办法了,也不可能保证唯一性,嗬嗬,如果有那东西,那不是所有的文件都可以压缩成16字节的文件了吗?上面是一个HMACSHA1的加密。