旧版的流 API(Node.js v0.10 之前)
加密模块是在 Node.js 出现统一的流 API 概念之前添加的,在 Buffer
对象用于处理二进制数据之前。
因此,许多 crypto
定义的类具有在其他实现流 API 的 Node.js 类(例如 update()
、final()
或 digest()
)上通常找不到的方法。
此外,许多方法默认接受并返回 'latin1'
编码字符串,而不是 Buffer
。
此默认值在 Node.js v0.8 之后更改为默认使用 Buffer
对象。
The Crypto module was added to Node.js before there was the concept of a
unified Stream API, and before there were Buffer
objects for handling
binary data. As such, the many of the crypto
defined classes have methods not
typically found on other Node.js classes that implement the streams
API (e.g. update()
, final()
, or digest()
). Also, many methods accepted
and returned 'latin1'
encoded strings by default rather than Buffer
s. This
default was changed after Node.js v0.8 to use Buffer
objects by default
instead.