我正在尝试使用节点加密提供的 aes-128-gcm 来实现加密/解密功能。根据我的理解,gcm 会加密密文,但也会对其进行哈希处理,并将其提供为“身份验证标签”。但是,我不断收到错误:“状态不受支持或无法验证数据”。
我不确定这是否是我的代码中的错误 - 查看加密的密文和身份验证标记,解密函数获取的密文与加密函数生成的密文和身份验证标记相同。
function encrypt(plaintext) {
// IV is being generated for each encryption
var iv = crypto.randomBytes(12),
cipher = crypto.createCipheriv(aes,key,iv),
encryptedData = cipher.update(plaintext),
tag;
// Cipher.final has been called, so no more encryption/updates can take place
encryptedData += cipher.final();
// Auth tag must be generated after cipher.final()
tag = cipher.getAuthTag();
return encryptedData + "$$" + tag.toString('hex') + "$$" + iv.toString('hex');
}
function decrypt(ciphertext) {
var cipherSplit = ciphertext.split("$$"),
text = cipherSplit[0],
tag = Buffer.from(cipherSplit[1], 'hex'), …Run Code Online (Sandbox Code Playgroud) 我正在尝试访问Polymer自定义元素中包含的Javascript方法<general-element>.此元素包含打开和关闭面板的功能.
这个通用元素在更具体的元素中使用,例如:<specific-element></specific-element>.特定元素包含常规元素并向其添加属性,即:面板标题等.
但是,在<specific-element>页面中使用时,我无法通过它调用任何打开/关闭方法.我是从错误的方式接近这个,有没有办法做到这一点?
编辑:代码示例
删除了一些Polymer代码 - 示例只是为了说明元素如何协同工作
一般元素:
<dom-module id="general-element">
<template>
// Code to define a slide-in panel
</template>
<script>
_openPanel: function() {
//Apply class to make panel visible
},
_closePanel: function() {
// Apply class to hide panel
}
</script>
</dom-module>
Run Code Online (Sandbox Code Playgroud)
具体要素:
<dom-module id="specific-element">
<template>
<general-element title="Administration Panel" >
<h1>Hello</h1>
</general-element>
</template>
</dom-module>
Run Code Online (Sandbox Code Playgroud)
用法:
<dom-module id="admin-page">
<template>
<button on-click="openPanel"></button>
<specific-element></specific-element>
</template>
<script>
openPanel: function() {
// Trying to call general-element _openPanel method
} …Run Code Online (Sandbox Code Playgroud)