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 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 :: regex generator from text 
Javascript :: curl --post with api 
Javascript :: accessing state in nuxt vuex 
Javascript :: uploading form data using axios to back end server such as node js 
Javascript :: Cannot coerce `dirty` to string because boolean [1] should not be coerced. 
Javascript :: GLTF position three.js 
Javascript :: click outside button angular 
Javascript :: create a friend component react js 
Javascript :: rechart graph 
Javascript :: fetch Mongodb find() results with Backbone 
Javascript :: convert object to array online javascript 
Javascript :: Tow sums 
Javascript :: odoo owl usestate 
Javascript :: draft save using jquery 
Javascript :: removes all item occurrences in array 
Javascript :: store in memory an array (two-dimensional) 10rows x 10columns with random integers and show the number of elements between 10 and 20 javvascript 
Javascript :: Creatable Multiselect 
Javascript :: use stigviewr 
Javascript :: move an object in array by latest clicked 
Javascript :: get data from json key with special character 
Javascript :: get a nodes path alias 
Javascript :: passing third parameter in context.commit vuejs 
Javascript :: react createelement data attribute 
Javascript :: js Changing selected option by option id, class, or attribute 
Javascript :: declare multiple variable javascript 
Javascript :: regex for erlang online 
Javascript :: delete file firebase angular 
Javascript :: correct code for the { "vars": "local" } 
Javascript :: how to compile javascript class 
Javascript :: Reversing the elements in an array-like object 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =