Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

encrypt decrypt javascript

const Cryptr = require('cryptr');
const cryptr = new Cryptr('ReallySecretKey');

const encryptedString = cryptr.encrypt('Popcorn');
const decryptedString = cryptr.decrypt(encryptedString);

console.log(encryptedString);
Comment

javascript string encryption and decryption

var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
//U2FsdGVkX18ZUVvShFSES21qHsQEqZXMxQ9zgHy+bu0=

var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
//4d657373616765


document.getElementById("demo1").innerHTML = encrypted;
document.getElementById("demo2").innerHTML = decrypted;
document.getElementById("demo3").innerHTML = decrypted.toString(CryptoJS.enc.Utf8);
Comment

javaScript encryption decryption

const baseString = 'konrad';
const encodedString = window.btoa( baseString ); // "a29ucmFk"
const decodedString = window.atob( encodedString ); //konrad
Comment

javascript encrypt decrypt

const cipher = salt => {
    const textToChars = text => text.split('').map(c => c.charCodeAt(0));
    const byteHex = n => ("0" + Number(n).toString(16)).substr(-2);
    const applySaltToChar = code => textToChars(salt).reduce((a,b) => a ^ b, code);

    return text => text.split('')
      .map(textToChars)
      .map(applySaltToChar)
      .map(byteHex)
      .join('');
}
    
const decipher = salt => {
    const textToChars = text => text.split('').map(c => c.charCodeAt(0));
    const applySaltToChar = code => textToChars(salt).reduce((a,b) => a ^ b, code);
    return encoded => encoded.match(/.{1,2}/g)
      .map(hex => parseInt(hex, 16))
      .map(applySaltToChar)
      .map(charCode => String.fromCharCode(charCode))
      .join('');
}

// To create a cipher
const myCipher = cipher('mySecretSalt')

//Then cipher any text:
console.log(myCipher('the secret string'))

//To decipher, you need to create a decipher and use it:
const myDecipher = decipher('mySecretSalt')
console.log(myDecipher("7c606d287b6d6b7a6d7c287b7c7a61666f"))
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: update node js 
Javascript :: jquery add to array with key 
Javascript :: min and max javascript 
Javascript :: request entity too large express 
Javascript :: .env.development.local 
Javascript :: javascript how to get subarray 
Javascript :: flatten an array javascript 
Javascript :: get zipcode from google places autocomplete 
Javascript :: date format french js 
Javascript :: untrack package-lock.json 
Javascript :: queryselector javascript 
Javascript :: string concat javascript 
Javascript :: react alert popup 
Javascript :: how to print in a same line in javascript 
Javascript :: js sort 
Javascript :: convert inches to feet javascript 
Javascript :: how to convert string to snake case in javascript 
Javascript :: how to delay something in javascript 
Javascript :: capitalize first carater js 
Javascript :: Send Form Data Using Ky AJAX 
Javascript :: swapping variables js 
Javascript :: open new window javascript 
Javascript :: Example: Export a Variable in Node 
Javascript :: nested for loop js 
Javascript :: ajax actions wordpress 
Javascript :: how to open a new browser window using a .bat 
Javascript :: js array.splice first element 
Javascript :: media queries generator script 
Javascript :: how to convert string into binary in javascript 
Javascript :: bson to json converter 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =