@absolunet/tweetnacl 中文文档教程
@absolunet/tweetnacl
TweetNaCl 包装器
包装 TweetNaCl 功能
Install
$ npm install @absolunet/tweetnacl
Usage
// Node.js
const tweetnacl = require('@absolunet/tweetnacl');
// Browser
// Load TweetNaCl libraries
// - /node_modules/tweetnacl/nacl-fast.js
// - /node_modules/tweetnacl-util/nacl-util.js
const { tweetnacl } = window.kafe;
// Lock the box
const { box, key } = tweetnacl.secretbox.lock('Dirty little secret');
console.log({ box, key });
// Outputs:
// {
// box: "ThyOjmYtUvWSGne8lxXK7sJWGc/oigJ+I51pauSN/xTLpoufdAVNcCCQmtnwHlsu/hD7xnNZr7snkW4="
// key: "ri4kzZ4V1pMGhGLqeqQayT3m2yT8FY79e1snqp2UAFg="
// }
// Unlock the box
const message = tweetnacl.secretbox.unlock(box, key);
console.log(message);
// Outputs:
// Dirty little secret
API
secretbox.lock(message)
包装 nacl.secretbox
自动生成 nonce
和 <代码>密钥
返回具有 box
和 key
的 String
属性的 Object
message
Required
类型:字符串
要锁定的消息
secretbox.unlock(box, key)
换行 nacl.secretbox.open< /code>
从 box
中自动提取 nonce
返回 String
消息
box
必需
类型:字符串
包含加密消息和随机数的框
key
必需
类型:字符串
解锁盒子的钥匙
License
MIT © Absolunet
@absolunet/tweetnacl
TweetNaCl wrapper
Wrap TweetNaCl functionalities
Install
$ npm install @absolunet/tweetnacl
Usage
// Node.js
const tweetnacl = require('@absolunet/tweetnacl');
// Browser
// Load TweetNaCl libraries
// - /node_modules/tweetnacl/nacl-fast.js
// - /node_modules/tweetnacl-util/nacl-util.js
const { tweetnacl } = window.kafe;
// Lock the box
const { box, key } = tweetnacl.secretbox.lock('Dirty little secret');
console.log({ box, key });
// Outputs:
// {
// box: "ThyOjmYtUvWSGne8lxXK7sJWGc/oigJ+I51pauSN/xTLpoufdAVNcCCQmtnwHlsu/hD7xnNZr7snkW4="
// key: "ri4kzZ4V1pMGhGLqeqQayT3m2yT8FY79e1snqp2UAFg="
// }
// Unlock the box
const message = tweetnacl.secretbox.unlock(box, key);
console.log(message);
// Outputs:
// Dirty little secret
API
secretbox.lock(message)
Wraps nacl.secretbox
with autogeneration of nonce
and key
Returns an Object
with String
properties of box
and key
message
Required
Type: String
Message to lock
secretbox.unlock(box, key)
Wraps nacl.secretbox.open
with autoextraction of nonce
from box
Returns a String
message
box
Required
Type: String
Box containing encrypted message and nonce
key
Required
Type: String
Key to unlock box
License
MIT © Absolunet