我正在尝试使用Jose.JWT.encode(payload, secretKey, JwsAlgorithm.ES256, header)(请参阅https://github.com/dvsekhvalnov/jose-jwt)生成 JWT 令牌,以与 Apple 的新的基于令牌的 APNs 系统一起使用。
JWT 编码方法要求 SecretKey 格式正确CngKey。这是我将 .p8 文件从 Apple 转换为CngKey对象的代码:
var privateKeyContent = System.IO.File.ReadAllText(authKeyPath);
var privateKey = privateKeyContent.Split('\n')[1];
//convert the private key to CngKey object and generate JWT
var secretKeyFile = Convert.FromBase64String(privateKey);
var secretKey = CngKey.Import(secretKeyFile, CngKeyBlobFormat.Pkcs8PrivateBlob);
Run Code Online (Sandbox Code Playgroud)
但是,在最后一行,抛出以下错误。
System.Security.Cryptography.CryptographicException was unhandled by user code
HResult=-2146885630
Message=An error occurred during encode or decode operation.
Source=System.Core
StackTrace:
at System.Security.Cryptography.NCryptNative.ImportKey(SafeNCryptProviderHandle provider, Byte[] keyBlob, String format)
at System.Security.Cryptography.CngKey.Import(Byte[] …Run Code Online (Sandbox Code Playgroud) 有一个页面在渲染时发出多个HTTP获取数据请求。如何过滤moxios.requests以获取具有特定URL的请求以进行响应?
我可以在网上找到的唯一方法是moxios.requests.mostRecent(),但是我不确定最近的请求是什么。即使这样,还有另一种方法可以弹出另一个请求吗?
此处的moxios库上似乎没有任何文档:https : //github.com/axios/moxios
let request = moxios.requests.mostRecent() // How to get 'some/url/' here? This expect is currently failing
expect(request.url).to.equal('some/url/')
request.respondWith({
status: 200,
response: []
}
Run Code Online (Sandbox Code Playgroud)