简体   繁体   English

加密模块在 IBM API Connect 中不起作用

[英]crypto module is not working in IBM API Connect

In IBM API Connect I am trying to use 'crypto' module in IBM API Connect gatewayscript.在 IBM API Connect 中,我尝试在 IBM API Connect 网关脚本中使用“加密”模块。 When I tested whether the crypto module is supported in gatewascript or not, I got the response as below当我测试gatewascript是否支持crypto模块时,我得到如下响应

Code in Gatewayscript:网关脚本中的代码:

var crypto = require('crypto');
session.output.write(crypto);

Output:输出:

*{
  "getHashes": {},
  "getCiphers": {},
  "createHash": {},
  "createHmac": {},
  "createSign": {},
  "createVerify": {},
  "createCipheriv": {},
  "createDecipheriv": {},
  "randomBytes": {}
}*

But when I tried to make use of it, I got 500 Internal Server Error:但是当我尝试使用它时,我收到了 500 Internal Server Error:

Code:代码:

var crypto = require('crypto');
var key = "Alice";

var hmac = crypto.createHmac('hmac-sha256', key);
var input = "This is plaintext to hash";
var result = hmac.update(input).digest('base64');

session.output.write(result);

output:输出:

  {
      "httpCode": "500",
      "httpMessage": "Internal Server Error",
      "moreInformation": "Internal Error"
    }

Not sure where the things are going wrong.不知道哪里出了问题。 I am copy pasting exact example from IBM website.我是从 IBM 网站复制粘贴确切示例。 Here is the reference to crypto: https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/crypto_js.html#crypto.createHmac以下是对加密的引用: https : //www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/crypto_js.html#crypto.createHmac

By using var key = "Alice";通过使用var key = "Alice"; you tell the datapower to use the sharedkey stored with alias 'Alice'.您告诉 datapower 使用以别名“Alice”存储的共享密钥。

If you want to use the 'Alice' string then you need to use a buffer like var key = new Buffer("Alice");如果你想使用 'Alice' 字符串,那么你需要使用像var key = new Buffer("Alice");

Nevertheless it won't work as HMAC expects a 160 bits key for hmac-sha1.然而它不会工作,因为 HMAC 期望 hmac-sha1 有一个 160 位的密钥。 You can generate it like that你可以这样生成

$ dd if=/dev/random count=20 bs=1 | xxd -ps
a73e3406e7dcc5fc168d9ae9954ec6e0d85e4444

20 as 20 Bytes (20x8 bits=160 bits) 20 为 20 字节(20x8 位=160 位)

If you want to store it in a shared object you can follow what's describe here : http://rcbj.net/blog01/2012/03/17/generating-and-uploading-a-shared-key-symmetric-key-to-datapower-appliances/如果你想将它存储在一个共享对象中,你可以按照这里的描述进行操作: http : //rcbj.net/blog01/2012/03/17/generating-and-uploading-a-shared-key-symmetric-key-to -数据电源设备/

Put the hex string generated by this command into a file called secret.key.将此命令生成的十六进制字符串放入名为secret.key 的文件中。 Upload the key to the cert:/// directory on the appliance.将密钥上传到设备上的 cert:/// 目录。 Navigate to Objects->Crypto Configuration->Crypto Shared Secret Key.导航到对象-> 加密配置-> 加密共享密钥。 Click Add.单击添加。 Enter a name for the shared key.输入共享密钥的名称。 From the drop down, chose the secret.key file that was uploaded a moment ago.从下拉菜单中选择刚才上传的secret.key 文件。 Click Apply.单击应用。 If no errors are displayed, the key was successfully read.如果未显示错误,则密钥已成功读取。 Click Save.单击保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM