小编Hel*_*len的帖子

C# - 尝试使用导入方法从 .p8 文件创建 CngKey,抛出错误“编码或解码操作期间发生错误”。

我正在尝试使用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)

c# jwt cng

3
推荐指数
1
解决办法
3259
查看次数

Moxios:如何访问不是单元测试中最新的请求

有一个页面在渲染时发出多个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)

axios moxios

2
推荐指数
1
解决办法
2200
查看次数

标签 统计

axios ×1

c# ×1

cng ×1

jwt ×1

moxios ×1