1.0.2 • Published 4 years ago
cryptojs2 v1.0.2
cryptojs2
JavaScript library of crypto standards.
Node.js (Install)
Requirements:
- Node.js
npm install cryptojs2Usage
Node.js
import sha256 from 'cryptojs2/sha256';
import hmacSHA256 from 'cryptojs2/hmac-sha256';
//or
import {SHA256 as sha256,HmacSHA256 as hmacSha256} from "cryptojs2";
const message, nonce, path, privateKey; // ...
const hashDigest = sha256(nonce + message);
const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));Client (browser)
Requirements:
Usage
Modular include:
Usage without RequireJS
<script type="module">
import sha256 from 'cryptojs2/sha256';
import hmacSHA256 from 'cryptojs2/hmac-sha256';
//or
import {SHA256 as sha256,HmacSHA256 as hmacSha256} from "cryptojs2";
window.sha256 = sha256; //FOR USE ALL DOCUMENT
window.hmacSHA256 = hmacSHA256; //FOR USE ALL DOCUMENT
var hashSHA256 = sha256("Message");
var hashhmacSha256 =hmacSha256("stringToSign", "signingKey");
</script>AES Encryption
Plain text encryption
import aes from 'cryptojs2/AES';
import hmacSHA256 from 'cryptojs2/hmac-sha256';
// Encrypt
var ciphertext = aes.encrypt('message', 'secret key').toString();
// Decrypt
var bytes = aes.decrypt(ciphertext, 'secret key');
var originalText = bytes.toString();
console.log(originalText); // 'message'Object encryption
import aes from 'cryptojs2/AES';
var data = [{id: 1}, {id: 2}]
// Encrypt
var ciphertext = aes.encrypt(JSON.stringify(data), 'secret key 123').toString();
// Decrypt
var bytes = aes.decrypt(ciphertext, 'secret key 123');
var decryptedData = JSON.parse(bytes.toString());
console.log(decryptedData); // [{id: 1}, {id: 2}]List of modules
cryptojs2/md5cryptojs2/sha1cryptojs2/sha256cryptojs2/sha224cryptojs2/sha512cryptojs2/sha384cryptojs2/sha3cryptojs2/ripemd160
cryptojs2/hmac-md5cryptojs2/hmac-sha1cryptojs2/hmac-sha256cryptojs2/hmac-sha224cryptojs2/hmac-sha512cryptojs2/hmac-sha384cryptojs2/hmac-sha3cryptojs2/hmac-ripemd160
cryptojs2/pbkdf2
cryptojs2/aescryptojs2/tripledescryptojs2/rc4cryptojs2/rabbitcryptojs2/rabbit-legacy
License
MIT license; see LICENSE.