我正在使用nodejs插件编写PKCS11加密包装器ffi、ref、ref-struct和ref-array。我有这个密码。
var hSession = this.session.handle;
var hObject = this.handle;
var $label = new (arrayType(cki.CK_UTF8CHAR))(80);
var template = new (arrayType(cki.CK_ATTRIBUTE))(1);
template[0] = new cki.CK_ATTRIBUTE({
type:cki.CKA_LABEL,
pValue: $label.ref(),
ulValueLen: 80})
var res = this.cki.C_GetAttributeValue(hSession, hObject, template.ref(), 1);
if (res == cki.CKR_OK) {
console.log("Ok");
}
else{
console.log("Wrong "+res);
}当我调用这个函数时,我得到了错误的结果(CKR_ARGUMENTS_BAD,CKR_ATTRIBUTE_TYPE_INVALID)。请帮我找出错误。
FFI函数
"C_GetAttributeValue":[t.CK_RV, [t.CK_SESSION_HANDLE, t.CK_OBJECT_HANDLE, t.CK_ATTRIBUTE_PTR, t.CK_ULONG]],类型
/* CK_ATTRIBUTE is a structure that includes the type, length
* and value of an attribute */
t.CK_ATTRIBUTE = struct({
type: t.CK_ATTRIBUTE_TYPE,
pValue: t.CK_VOID_PTR,
/* ulValueLen went from CK_USHORT to CK_ULONG for v2.0 */
ulValueLen: t.CK_ULONG /* in bytes */
});
发布于 2015-10-03 21:36:07
(发言全文载於评论)
使用纯Buffer提供缓冲区来存储属性值:
var $label = new Buffer(80);在结构中传递它如下:
template[0] = new cki.CK_ATTRIBUTE({
type:cki.CKA_LABEL,
pValue: $label,
ulValueLen: $label.length}) 然后使用$label.toString('utf8',0,<ulValueLen>)获取实际字符串。
注:我不精通Node,但这种方法似乎奏效了。
https://stackoverflow.com/questions/32703273
复制相似问题