1. //需要添加命名空间
    2. System.Security.Cryptography;
    3. System.Text;
    4. //=========================================================================================
    5. /// <summary>
    6. /// 字符串混淆器
    7. /// </summary>
    8. /// <param name="str">要混淆的字符串</param>
    9. /// <param name="ints">长度为16的整型数组,要求0到30,可重复</param>
    10. /// <param name="chars">长度为小于等于32的字符数组,字符可为任意字符,参与字符打乱</param>
    11. /// <returns></returns>
    12. public static string Confused(string strs, int[] ints, char[] chars)
    13. {
    14. string strchange = "";
    15. MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    16. //获取到的str转成UTF8编码的字节数组,转成字节数组后才能放到md5.ComputeHash这个里面
    17. byte[] bytes1 = Encoding.UTF8.GetBytes(strs);
    18. string str = BitConverter.ToString(md5.ComputeHash(bytes1)).ToLower().Replace("-", "");
    19. foreach (int item in ints)
    20. {
    21. strchange += str.Substring(item, 2);
    22. }
    23. char[] chararray = strchange.ToCharArray();
    24. string ConfusedStr = "";
    25. for (int i = 0; i < chars.Length; i++)
    26. {
    27. ConfusedStr += ((int)chararray[i]).ToString() + ((int)chars[i]).ToString();
    28. }
    29. byte[] bytes2 = Encoding.UTF8.GetBytes(ConfusedStr);
    30. return BitConverter.ToString(md5.ComputeHash(bytes2)).ToLower().Replace("-", "");
    31. }
    32. //=========================================================================================