1.0.6 • Published 5 years ago

crypto-tiny v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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);

}

});

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago