问题描述
我是JavaScript或GatewayScript的新手.我有一个需要将.pem(位于DataPower中local:///cert下或可以添加到加密对象中)的内容转换为JWK的要求.
I am a newbie in JavaScript or 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.
任何人都可以帮助我了解如何开发JavaScript的起点
Could anyone help me with the starting point on how to develop a javascript to
- 从DataPower引用加密密钥对象(示例加密密钥)对象JWKCryptoCertObj)
- 解密加密密钥对象(示例JWKCryptoCertObj.pem)
- 将密钥的内容转换为JSON Web密钥(
jwk.readCertificate()
)
- refer the crypto key object from DataPower (example crypto keyobject JWKCryptoCertObj)
- Decrypt the crypto key object (exampleJWKCryptoCertObj.pem)
- Convert the content of the key to JSON Web Key (
jwk.readCertificate()
)
到目前为止,我已经知道jwk.readCertificate()
可以帮助我将密钥对象转换为JWK.
So far I have got to know that jwk.readCertificate()
can help me to convert a key object to a JWK.
我已经尝试了以下代码来获取它:
I have tried the below piece of code to fetch it:
var jwk = require('jwk');var myJWK = jwk.readCertificate('cerjwk');console.log(myJWK);
var jwk = require('jwk');var myJWK = jwk.readCertificate('cerjwk');console.log(myJWK);
但是,我在DataPower中遇到以下错误:
However, I get the below error in 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!!
推荐答案
无需转换证书.只需将其添加到Crypto Key
对象中,然后在调用中使用该对象的名称(例如"crykey-my-key")即可,例如:
There is no need to convert the certificate. Just add it into a Crypto Key
object and use the name (e.g. "crykey-my-key") of the object in the call, e.g.:
const jwk = require('jwk');
const myKeyJWK = jwk.readCertificate('crykey-my-key');
这篇关于使用JavaScript的JSON Web密钥的加密密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!