using System.Security.Cryptography; using System.Text; using UnityEngine; namespace WS { ///异或 Sha1 public class OtherEncrypt { /// 异或因子 private static readonly byte[] xorScale = new byte[] { 45, 66, 38, 55, 23, 254, 9, 165, 90, 19, 41, 45, 201, 58, 55, 37, 254, 185, 165, 169, 19, 171 }; /// 随机字符串 private static readonly string[] RandomScale = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*","+","-","/",".",">","<","&","%","#","@","$","!","^", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; ///异或 public static byte[] Xor(byte[] buffer) { int iScaleLen = xorScale.Length; for (int i = 0; i < buffer.Length; i++) { buffer[i] = (byte)(buffer[i] ^ xorScale[i % iScaleLen]); } return buffer; } ///Sha1 加密 public static string Sha1(string str) { byte[] buffer = Encoding.Default.GetBytes(str); byte[] data = SHA1.Create().ComputeHash(buffer); StringBuilder sub = new StringBuilder(); foreach (var t in data) { sub.Append(t.ToString("X2")); } return sub.ToString(); } ///获取随机字符串 public static string GetRandomString(int count) { int maxcount = RandomScale.Length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { int index = Random.Range(0, maxcount); sb.Append(RandomScale[index]); } return sb.ToString(); } } }