Node.js 中的 decipher.update() 方法
decipher.update()用于根据给定的编码格式用接收到的数据更新解密。它是 crypto 模块中的 Decipher 类提供的内置方法之一。如果指定了输入编码,则数据参数是字符串,否则数据参数是缓冲区
语法
decipher.update(data, [inputEncoding], [outputEncoding])
参数
以上参数描述如下 -
data – 它需要数据作为传递以更新解密内容的输入。
inputEncoding - 它将输入编码作为参数。可能的输入值为十六进制、base64 等。
outputEncoding – 它将输出编码作为参数。该参数的输入类型是字符串。可能的输入值为十六进制、base64 等。
示例
创建一个名为 decipherUpdate.js 的文件并复制以下代码片段。创建文件后,使用以下命令运行此代码,如下例所示 -
node decipherUpdate.js
decipherUpdate.js
// Example to demonstrate the use of decipher.final() method // Importing the crypto module const crypto = require('crypto'); // Initialising the AES algorithm const algorithm = 'aes-192-cbc'; // Initialising the password used for generating key const password = '12345678123456789'; // Retrieving key for the decipher object const key = crypto.scryptSync(password, 'old data', 24); // Initializing the static iv const iv = Buffer.alloc(16, 0); const decipher = crypto.createDecipheriv(algorithm, key, iv); // Initializing the decipher object to get decipher const encrypted = '083bfe1b2f91677e5d00add115be2f1b2e362e190406f5c6b60e86969bf03bff'; // const encrypted2 = '8d11772fce59f08e7558db5bf17b3112'; let decryptedValue = decipher.update(encrypted, 'hex', 'utf8'); // let decryptedValue1 = decipher.update(encrypted1, 'hex', 'utf8'); decryptedValue += decipher.final('utf8'); // Printing the result... console.log("Decrypted value -- " + decryptedValue); // console.log("Base64 String:- " + base64Value)
输出
C:\homeode>> node decipherUpdate.js Decrypted value -- Some new text data
示例
让我们再看一个示例。
// Example to demonstrate the use of decipher.final() method // Importing the crypto module const crypto = require('crypto'); // Initialising the AES algorithm const algorithm = 'aes-192-cbc'; // Initialising the password used for generating key const password = '12345678123456789'; // Retrieving key for the decipher object crypto.scrypt(password, 'salt', 24, { N: 512 }, (err, key) => { if (err) throw err; // Initializing the static iv const iv = Buffer.alloc(16, 0); // Initializing the decipher with algo, key and iv const decipher = crypto.createDecipheriv(algorithm, key, iv); const encrypted = '91d6d37e70fbae537715f0a921d15152194435b96ce3973d92fbbc4a82071074'; //Getting the decrypted string value const decrypted = decipher.update(encrypted, 'hex', 'utf8'); // Printing the result... console.log("Decrypted value:- " + decrypted); });
输出
C:\homeode>> node decipherUpdate.js Decrypted value:- Some new text data
以上是Node.js 中的 decipher.update() 方法的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

JavaScript字符串替换方法详解及常见问题解答 本文将探讨两种在JavaScript中替换字符串字符的方法:在JavaScript代码内部替换和在网页HTML内部替换。 在JavaScript代码内部替换字符串 最直接的方法是使用replace()方法: str = str.replace("find","replace"); 该方法仅替换第一个匹配项。要替换所有匹配项,需使用正则表达式并添加全局标志g: str = str.replace(/fi

本教程向您展示了如何将自定义的Google搜索API集成到您的博客或网站中,提供了比标准WordPress主题搜索功能更精致的搜索体验。 令人惊讶的是简单!您将能够将搜索限制为Y

本文系列在2017年中期进行了最新信息和新示例。 在此JSON示例中,我们将研究如何使用JSON格式将简单值存储在文件中。 使用键值对符号,我们可以存储任何类型的

增强您的代码演示:开发人员的10个语法荧光笔 在您的网站或博客上共享代码片段是开发人员的常见实践。 选择合适的语法荧光笔可以显着提高可读性和视觉吸引力。 t

因此,在这里,您准备好了解所有称为Ajax的东西。但是,到底是什么? AJAX一词是指用于创建动态,交互式Web内容的一系列宽松的技术。 Ajax一词,最初由Jesse J创造

利用轻松的网页布局:8个基本插件 jQuery大大简化了网页布局。 本文重点介绍了简化该过程的八个功能强大的JQuery插件,对于手动网站创建特别有用

核心要点 JavaScript 中的 this 通常指代“拥有”该方法的对象,但具体取决于函数的调用方式。 没有当前对象时,this 指代全局对象。在 Web 浏览器中,它由 window 表示。 调用函数时,this 保持全局对象;但调用对象构造函数或其任何方法时,this 指代对象的实例。 可以使用 call()、apply() 和 bind() 等方法更改 this 的上下文。这些方法使用给定的 this 值和参数调用函数。 JavaScript 是一门优秀的编程语言。几年前,这句话可

本文介绍了关于JavaScript和JQuery模型视图控制器(MVC)框架的10多个教程的精选选择,非常适合在新的一年中提高您的网络开发技能。 这些教程涵盖了来自Foundatio的一系列主题
