using System; using System.Security.Cryptography; using System.Text; namespace TeamAAS { /// /// GUID 工具。根据字符串生成确定性 GUID(同一输入永远得到同一 GUID), /// 供插件 ID、类型 Key 等场景跨项目复用。 /// public static class GuidGenerator { /// /// 根据传入值生成确定性 GUID /// public static Guid GenerateGuidFromValue(string value) { if (string.IsNullOrEmpty(value)) throw new ArgumentException("值不能为空", nameof(value)); // 使用 SHA1 哈希(20 字节),取前 16 字节构建 GUID using (var sha1 = SHA1.Create()) { byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(value)); byte[] guidBytes = new byte[16]; Array.Copy(hash, guidBytes, 16); // 截取前 16 字节 return new Guid(guidBytes); } } } }