I want to Encode number to character.
Code:
const CryptoJS = require('crypto-js');
function msg() {
return '7543275'; // I want to encrypt this number to character
}
const msgLocal = msg();
// Encrypt
const ciphertext = CryptoJS.AES.encrypt(msgLocal, 'password');
// Decrypt
const bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'password');
const plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log(plaintext);
Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.
Encode to Base64 formatSimply enter your data then push the encode button. To encode binaries (like images, documents, etc.) use the file upload form a little further down on this page. Destination character set. Destination newline separator.
CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. They are fast, and they have a consistent and simple interface.
Solved.
const CryptoJS = require('crypto-js');
// OUTPUT
console.log(encode()); // 'NzUzMjI1NDE='
console.log(decode()); // '75322541'
function encode() {
// INIT
const myString = '75322541'; // Utf8-encoded string
// PROCESS
const encodedWord = CryptoJS.enc.Utf8.parse(myString); // encodedWord Array object
const encoded = CryptoJS.enc.Base64.stringify(encodedWord); // string: 'NzUzMjI1NDE='
return encoded;
}
function decode() {
// INIT
const encoded = 'NzUzMjI1NDE='; // Base64 encoded string
// PROCESS
const encodedWord = CryptoJS.enc.Base64.parse(encoded); // encodedWord via Base64.parse()
const decoded = CryptoJS.enc.Utf8.stringify(encodedWord); // decode encodedWord via Utf8.stringify() '75322541'
return decoded;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With