UNPKG

smartledger-sdk

Version:

A comprehensive blockchain and cryptographic operations SDK for JavaScript

28 lines (25 loc) 774 B
import CryptoJS from "crypto-js"; class Encryption { //simple encryption with AES static encrypt(data, key) { const ciphertext = CryptoJS.AES.encrypt( JSON.stringify(data), key ).toString(); return ciphertext; } static decrypt(ciphertext, key) { const bytes = CryptoJS.AES.decrypt(ciphertext, key); const decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); return decryptedData; } } // Example const key = "my-secret-key"; const data = { message: "Hello, World!" }; const encryptedData = Encryption.encrypt(data, key); console.log("Encrypted:", encryptedData); const decryptedData = Encryption.decrypt(encryptedData, key); console.log("Decrypted:", decryptedData); export default Encryption; export { Encryption };