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 :: angular pass async pipe value to funciton 
Javascript :: javascript insertbefore 
Javascript :: Prevent Double tap in React native 
Javascript :: search string javascript 
Javascript :: mongoose update subdocument by id 
Javascript :: google tuner 
Javascript :: dom event 
Javascript :: yup validation based on another field value 
Javascript :: jsp date 
Javascript :: get smallest value in array js 
Javascript :: convert array to csv javascript 
Javascript :: how to use post method axios 
Javascript :: angular subscribe on value change 
Javascript :: javascript string repeat 
Javascript :: multipart/form-data ajax jquery 
Javascript :: axios set request header 
Javascript :: add color to attribute using jquery 
Javascript :: vue router url string 
Javascript :: a scroll to div js 
Javascript :: remove an element from array javascript 
Javascript :: accessing nested objects in javascript 
Javascript :: material ui 
Javascript :: swr npm 
Javascript :: json to string dart 
Javascript :: how to create a class javascript 
Javascript :: Factorial Recursion Function in Javascript 
Javascript :: nested json schema mongoose 
Javascript :: react Spread Attributes conditionally 
Javascript :: spinner react native 
Javascript :: Using flat() method 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =