[英]Cryptographic key to JSON Web Key using javascript
I am a newbie in JavaScript or GatewayScript.我是 JavaScript 或 GatewayScript 的新手。 I have a requirement where I need to convert the content of a.pem (which is in DataPower under local:///cert or can be added into a crypto object) to JWK.
我有一个要求,我需要将 a.pem 的内容(位于 local:///cert 下的 DataPower 中,或者可以添加到加密对象中)到 JWK。
Could anyone help me with the starting point on how to develop a javascript to任何人都可以帮助我了解如何开发 javascript 到
jwk.readCertificate()
)jwk.readCertificate()
) So far I have got to know that jwk.readCertificate()
can help me to convert a key object to a JWK.到目前为止,我已经知道
jwk.readCertificate()
可以帮助我将密钥 object 转换为 JWK。
I have tried the below piece of code to fetch it:我已经尝试了下面的代码来获取它:
var jwk = require('jwk'); var myJWK = jwk.readCertificate('cerjwk'); console.log(myJWK);
However, I get the below error in DataPower:但是,我在 DataPower 中收到以下错误:
3:13:17 AM mpgw error 1277869681 error 0x00d30003 mpgw (PortTest): Rejected by filter; SOAP fault sent
3:13:17 AM multistep error 1277869681 request 0x80c00009 mpgw (PortTest): request PortTest_Policy_rule_1 #2 gatewayscript: Transforming the content of INPUT. The transformation local:///jwk.js is applied. The results are stored in testop. failed: Internal Error
3:13:17 AM gatewayscript error 1277869681 request 0x85800007 mpgw (PortTest): GatewayScript processing Error 'Error: Named certificate 'cerjwk' not found In file 'gatewayscript:///modules/jwk.js' line:428, stack:Error: Named certificate 'cerjwk' not found at Object.readCertificate (gatewayscript:///modules/jwk.js:428:18) at Object. (local:///jwk.js:5:17) at Script.execute (gatewayscript:///datapower.js:155:24) at Object. (gatewayscript:///datapower.js:582:55)'
3:13:17 AM crypto error 1277869681 request 0x8580005c mpgw (PortTest): Named certificate 'cerjwk' not found
Could anyone help me with the issue here?有人可以帮我解决这里的问题吗? Thanks in advance!!
提前致谢!!
There is no need to convert the certificate.无需转换证书。 Just add it into a
Crypto Key
object and use the name (eg "crykey-my-key") of the object in the call, eg:只需将其添加到
Crypto Key
object 并在调用中使用 object 的名称(例如“crykey-my-key”),例如:
const jwk = require('jwk');
const myKeyJWK = jwk.readCertificate('crykey-my-key');
It finally worked, the thing that was needed to be changed was the cert, instead of the key.它终于奏效了,需要更改的是证书,而不是密钥。
Here is the working code:这是工作代码:
var ctx = session.name('INPUT')|| session.createContext('INPUT');
var hm = require('header-metadata');
//var headers = hm.current;
var sm = require('service-metadata');
var uriIn=sm.getVar("var://service/URI");
var jwk = require('jwk');
var myJWK = jwk.readCertificate('qa.developer.citigroup.net');
//headers.set('X-new-header', myJWK);
//headers.set('Content-Type','application/json');
console.log(myJWK);
ctx.setVariable('yourjwk',myJWK);
session.output.write(myJWK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.