如何在自定义扩展程序javascript中调用HMac-Sha1?我需要为我的RESTful API生成自定义签名。
我需要使用Paw JS API从JavaScript调用中调用动态值。例如,我需要从我的JS代码计算HMAC + SHA1哈希,为此我认为使用现有的“HMAC-SHA1”动态值会很方便。
我该怎么做?
答案 0 :(得分:0)
您可以通过实例化新的DynamicValue
设置其值,将其包装在DynamicString
中并对其进行评估来实现。
注意,动态值本身尚未记录。但您拥有DynamicValue
和DynamicString
的文档。
以下是代码:
function evaluate(context){
// create a dynamic value of that type
var dv = DynamicValue('com.luckymarmot.HMACDynamicValue');
// set its properties
dv.algorithm = 1; // (not documented) algorithm = 1 for SHA1
dv.input = "Something to Hash"; // input string
dv.key = "HASH_KEY"; // HMAC key
// wrap in a (dynamic) string
var string = DynamicString(dv)
// evaluate the string
return string.getEvaluatedString();
};