感谢您的回答,不得不联系许多支持来完成这项工作.这是最终结果的样子.
////// Method returns ECDSA signed JWT token format, from json header, json payload and privateKey (pure string extracted from *.p8 file - PKCS#8 format) /// /// ECDSA256 key /// JSON header, i.e. "{\"alg\":\"ES256\" ,\"kid\":\"1234567899"\"}" /// JSON payload, i.e. {\"iss\":\"MMMMMMMMMM"\",\"iat\":"122222222229"}" ///base64url encoded JWT token public static string SignES256(string privateKey, string header, string payload) { CngKey key = CngKey.Import( Convert.FromBase64String(privateKey), CngKeyBlobFormat.Pkcs8PrivateBlob); using (ECDsaCng dsa = new ECDsaCng(key)) { dsa.HashAlgorithm = CngAlgorithm.Sha256; var unsignedJwtData = Url.Base64urlEncode(Encoding.UTF8.GetBytes(header)) + "." + Url.Base64urlEncode(Encoding.UTF8.GetBytes(payload)); var signature = dsa.SignData(Encoding.UTF8.GetBytes(unsignedJwtData)); return unsignedJwtData + "." + Url.Base64urlEncode(signature); } }