rename ticc.sign/verify/encrypt/decrypt/hash to ticc.xxx_easy
This commit is contained in:
parent
1d79a3b560
commit
cc01e71f48
14
ticc.js
14
ticc.js
@ -184,7 +184,7 @@ class TicCrypto {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static hash (data, { hasher = my.HASHER, salt, input = my.INPUT, output = my.OUTPUT } = {}) {
|
static hash_easy (data, { hasher = my.HASHER, salt, input = my.INPUT, output = my.OUTPUT } = {}) {
|
||||||
// data can be anything, but converts to string or remains be Buffer/TypedArray/DataView
|
// data can be anything, but converts to string or remains be Buffer/TypedArray/DataView
|
||||||
if (this.is_hashable({ data })) {
|
if (this.is_hashable({ data })) {
|
||||||
if (typeof data !== 'string' && !(data instanceof Buffer) && !(data instanceof DataView)) data = JSON.stringify(data)
|
if (typeof data !== 'string' && !(data instanceof Buffer) && !(data instanceof DataView)) data = JSON.stringify(data)
|
||||||
@ -208,7 +208,7 @@ class TicCrypto {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static async encrypt ({ data, tool = 'crypto', keytype = 'pwd', key, input, output, cipher } = {}) {
|
static async encrypt_easy ({ data, tool = 'crypto', keytype = 'pwd', key, input, output, cipher } = {}) {
|
||||||
if (tool === 'eccrypto') {
|
if (tool === 'eccrypto') {
|
||||||
// data 应当是 utf8 的字符串。key 必须是 pubkey
|
// data 应当是 utf8 的字符串。key 必须是 pubkey
|
||||||
// eccrypto 能用 Uint8Array 和 Buffer
|
// eccrypto 能用 Uint8Array 和 Buffer
|
||||||
@ -248,7 +248,7 @@ class TicCrypto {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static async decrypt ({ data = {}, tool = 'crypto', keytype = 'pwd', key, input, output, cipher } = {}) {
|
static async decrypt_easy ({ data = {}, tool = 'crypto', keytype = 'pwd', key, input, output, cipher } = {}) {
|
||||||
// data 应当是 encrypt 输出的数据类型
|
// data 应当是 encrypt 输出的数据类型
|
||||||
if (tool === 'eccrypto') {
|
if (tool === 'eccrypto') {
|
||||||
try {
|
try {
|
||||||
@ -297,7 +297,7 @@ class TicCrypto {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static async sign ({ data, seckey, tool = 'crypto', hasher }) {
|
static async sign_easy ({ data, seckey, tool = 'crypto', hasher }) {
|
||||||
// data can be string or buffer or object, results are the same
|
// data can be string or buffer or object, results are the same
|
||||||
if (this.is_hashable({ data }) && this.is_seckey(seckey)) {
|
if (this.is_hashable({ data }) && this.is_seckey(seckey)) {
|
||||||
if (tool === 'nacl' && seckey.length === 128) {
|
if (tool === 'nacl' && seckey.length === 128) {
|
||||||
@ -334,7 +334,7 @@ class TicCrypto {
|
|||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static async verify ({ data, signature, pubkey, tool = 'crypto', hasher }) {
|
static async verify_easy ({ data, signature, pubkey, tool = 'crypto', hasher }) {
|
||||||
// data could be anything, but converts to string or remains be Buffer/TypedArray/DataView
|
// data could be anything, but converts to string or remains be Buffer/TypedArray/DataView
|
||||||
if (this.is_hashable({ data }) && this.is_signature(signature) && this.is_pubkey({ pubkey })) {
|
if (this.is_hashable({ data }) && this.is_signature(signature) && this.is_pubkey({ pubkey })) {
|
||||||
if ('nacl' === tool && signature.length === 128) {
|
if ('nacl' === tool && signature.length === 128) {
|
||||||
@ -905,10 +905,10 @@ class TicCrypto {
|
|||||||
* @return {*}
|
* @return {*}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static randomize_keypair ({ tool, purpose } = {}) {
|
static randomize_keypair ({ tool, purpose = 'sign' } = {}) {
|
||||||
let kp
|
let kp
|
||||||
if (tool === 'nacl') {
|
if (tool === 'nacl') {
|
||||||
if (purpose === 'encrypt') {
|
if (purpose === 'secret') {
|
||||||
kp = nacl.box.keyPair()
|
kp = nacl.box.keyPair()
|
||||||
} else {
|
} else {
|
||||||
kp = nacl.sign.keyPair()
|
kp = nacl.sign.keyPair()
|
||||||
|
Loading…
Reference in New Issue
Block a user