using System.Security.Cryptography; using System.Xml.Linq; namespace Distribution.Infra.Authorization; /// /// Parses an XML-format RSA public key (`<RSAKeyValue>...</RSAKeyValue>`, as issued by /// AuthHex) into an instance. Written by hand instead of relying on /// RSA.FromXmlString, which is Windows-only in .NET (throws PlatformNotSupportedException on /// Linux/macOS) — this keeps token validation portable across hosts. /// public static class RsaXmlKeyReader { public static RSA ReadPublicKey(string xml) { var root = XElement.Parse(xml); var modulus = root.Element("Modulus")?.Value ?? throw new InvalidOperationException("RSA XML key is missing ."); var exponent = root.Element("Exponent")?.Value ?? throw new InvalidOperationException("RSA XML key is missing ."); var parameters = new RSAParameters { Modulus = Convert.FromBase64String(modulus), Exponent = Convert.FromBase64String(exponent) }; var rsa = RSA.Create(); rsa.ImportParameters(parameters); return rsa; } }