using System.Buffers.Binary; using Yuanshen.Common.Security.Util; namespace Yuanshen.Common.Security; public static class MhySecurity { public static byte[] InitialKey { get; } = new byte[0x1000]; public static byte[] GenerateSecretKey(ulong seed) { byte[] key = GC.AllocateUninitializedArray(0x1000); Span keySpan = key.AsSpan(); MT19937 mt = new(seed); for (int i = 0; i < 0x1000; i += 8) { BinaryPrimitives.WriteUInt64BigEndian(keySpan[i..], mt.Int63()); } return key; } public static void Xor(Span data, ReadOnlySpan key) { for (int i = 0; i < data.Length; i++) { data[i] ^= key[i % key.Length]; } } }