/// <summary> /// 随机生成密钥 /// </summary> /// <param name="n">位数</param> /// <returns></returns> private byte[] GetRandomKey(int n, int seed) { StringBuilder num = new StringBuilder(); FixRandom rnd = new FixRandom(seed); for (int i = 0; i < n; i++) { num.Append(arrChar[rnd.Range(0, arrChar.Length)].ToString()); } //NetDebug.Log("seed:"+ seed+ "生成密码:" +num); return(Encoding.UTF8.GetBytes(num.ToString())); }
public override byte[] Encryption(Session session, byte[] datas) { int index = 0; byte[] pwd = null; if (!session.ContainsAttributeKey(Key_Index)) { index = new FixRandom(DateTime.Now.Second).Range(1, 999999); session.SetAttribute(Key_Index, index); pwd = GetRandomKey(16, index); session.SetAttribute(Key_Password, pwd); } //NetDebug.Log("加密的Index:" + index); pwd = GetPassword(session, index); datas = Encrypt(pwd, datas); byte[] pBytes = bitConverter.GetBytes(index); byte[] allDatas = new byte[pBytes.Length + datas.Length]; pBytes.CopyTo(allDatas, 0); datas.CopyTo(allDatas, pBytes.Length); return(allDatas); }