public string CreateSignedToken(string data, string pemFile) { TimeSpan utcNow = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); double totalMilliseconds = utcNow.TotalMilliseconds + 30000; Dictionary <string, object> strs = new Dictionary <string, object>() { { "sub", "tester" }, { "exp", totalMilliseconds }, { "datas", this.GetMd5(data) } }; Dictionary <string, object> strs1 = strs; RSACryptoServiceProvider rSACryptoServiceProvider = Crypto.DecodeRsaPrivateKey(File.ReadAllText(pemFile), ""); return(JWT.Encode(strs1, rSACryptoServiceProvider, JwsAlgorithm.PS256, null)); }
/// <summary> /// 签名方式1 /// </summary> /// <param name="data">签名内容的json串格式</param> /// <param name="pemFile">私钥文件物理路径</param> /// <returns></returns> public string CreateSignedToken(string data, string pemFile) { var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); //5分钟内有效 var exp = ts.TotalMilliseconds + 30000; var payload = new Dictionary <string, object> { { "sub", "tester" }, { "exp", exp }, { "datas", GetMd5(data) } }; //string loadedRSA = File.ReadAllText("keys/private.rsa.pem"); string loadedRSA = File.ReadAllText(pemFile); RSACryptoServiceProvider privateRSAkey = Crypto.DecodeRsaPrivateKey(loadedRSA); var token = JWT.Encode(payload, privateRSAkey, JwsAlgorithm.PS256); return(token); }
public static string Encode(object payload, object key, JwsAlgorithm algorithm, IDictionary <string, object> extraHeaders = null) { return(JWT.Encode(JsonConvert.SerializeObject(payload), key, algorithm, extraHeaders)); }
public static string Encode(object payload, object key, JweAlgorithm alg, JweEncryption enc, JweCompression?compression = null, IDictionary <string, object> extraHeaders = null) { return(JWT.Encode(JsonConvert.SerializeObject(payload), key, alg, enc, compression, extraHeaders)); }