crypto-tiny

1.0.6 • Public • Published

crypto-tiny

ecc from eosjs-ecc

aes from crypto-js

install

bower install crypto-tiny

crypto Usage

const cryptoTiny = require('crypto-tiny').GetInstance();

//1. Encrypt(aes的加密)

var data_encrypt = cryptoTiny.Encrypt(message,key);

//2. Decrypt (aes的解密)

var data_decrypt = cryptoTiny.Decrypt(data_encrypt,key);

sign usage

const cryptoTiny = require('crypto-tiny').GetInstance();

//1. set key (私钥)

cryptoTiny.SignKey(signKey);

//2. sign (把数据签名)

var data = cryptoTiny.Sign(message);

//3. verify (data是个json对像)

cryptoTiny.Verify(data);

test

const cryptoTiny = require('./index').GetInstance();

function randomString(e) { e = e || 32; var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", a = t.length, n = ""; for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a)); return n }

function testSign(message, signKey){ var data = cryptoTiny.Sign(message,signKey); return cryptoTiny.Verify(data); }

function testDecrypt(message,key){

var data_encrypt = cryptoTiny.Encrypt(message,key);
var data_decrypt = cryptoTiny.Decrypt(data_encrypt,key);

return message=== data_decrypt;

}

for (let i=0; i<100; i++){

var tmp_msg = randomString(Math.floor(Math.random()*2048 + 1) );

var tmp_key = randomString( Math.floor(Math.random()*100 + 1) );

var ret = testDecrypt(tmp_msg, tmp_key);

console.warn("test crypt", i, ret);

}

cryptoTiny.NewSignKey().then(function (signKey) {

for (let i=0; i<10; i++){

    var tmp_msg = randomString(Math.floor(Math.random()*2048 + 1) );

    var ret = testSign(tmp_msg, signKey);

    console.warn("test sign", i, ret);

}

});

Readme

Keywords

Package Sidebar

Install

npm i crypto-tiny

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

5.18 kB

Total Files

4

Last publish

Collaborators

  • lei006