public static JwsPacket Encapsulate(PrivKey key, string?kid, string nonce, string url, object?payload) { JwsKey jwk = CreateJwsKey(key.PublicKey, out string algName, out string signerName); JwsProtected protect = new JwsProtected() { alg = algName, jwk = kid._IsEmpty() ? jwk : null, kid = kid._IsEmpty() ? null : kid, nonce = nonce, url = url, }; JwsPacket ret = new JwsPacket() { Protected = protect._ObjectToJson(base64url: true, includeNull: true), payload = (payload == null ? "" : payload._ObjectToJson(base64url: true)), }; var signer = key.GetSigner(signerName); byte[] signature = signer.Sign((ret.Protected + "." + ret.payload)._GetBytes_Ascii()); ret.signature = signature._Base64UrlEncode(); return(ret); }
public virtual async Task <WebRet> RequestWithJwsObject(WebMethods method, PrivKey privKey, string?kid, string nonce, string url, object?payload, CancellationToken cancel = default, string postContentType = Consts.MimeTypes.Json) { JwsPacket reqPacket = JwsUtil.Encapsulate(privKey, kid, nonce, url, payload); return(await this.RequestWithJsonObjectAsync(method, url, reqPacket, cancel, postContentType)); }