Package Exports
- crypto-tiny
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (crypto-tiny) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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);
}
});