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

encrypt decrypt in vanilla javascript

 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 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

encrypt in js

var secret = "My Secret Passphrase";
var plainText = "the brown fox jumped over the lazy dog";
var encrypted = CryptoJS.AES.encrypt(plainText, secret);
var decrypted = CryptoJS.AES.decrypt(encrypted, secret);

document.getElementById("m1").innerHTML = encrypted;
document.getElementById("m2").innerHTML = decrypted;
document.getElementById("m3").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

encrypt js

function getMessageEncoding() {
  const messageBox = document.querySelector(".rsa-oaep #message");
  let message = messageBox.value;
  let enc = new TextEncoder();
  return enc.encode(message);
}

function encryptMessage(publicKey) {
  let encoded = getMessageEncoding();
  return window.crypto.subtle.encrypt(
    {
      name: "RSA-OAEP"
    },
    publicKey,
    encoded
  );
}
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 :: how to implement redis pub sub model using nodejs 
Javascript :: tolocaledatestring format dd-mm-yyyy 
Javascript :: JavaScript Splitting a string using a regular expression 
Javascript :: create a binary tree 
Javascript :: default selected radio button angular material 
Javascript :: remove classname to node 
Javascript :: how to change root variable css 
Javascript :: add required attribute javascript 
Javascript :: jquery make visible 
Javascript :: hwo to make ana array of prime numbers in javascript 
Javascript :: how to pass the data from one page to another in javascript 
Javascript :: find input by value attribute javascript 
Javascript :: change datetime format in js 
Javascript :: javascript today date in epoch 
Javascript :: generate component in angular 
Javascript :: split 2 arrays javascript 
Javascript :: how to add a class to an element in javascript 
Javascript :: javascript get day 
Javascript :: js click anchor 
Javascript :: javascript multidimensional array foreach 
Javascript :: how to check input is selected or not 
Javascript :: get query parameters in node.js 
Javascript :: jquery set span text by id 
Javascript :: group all items with same name js 
Javascript :: js regex replace multiple matches 
Javascript :: store input into array javascript 
Javascript :: javascript calculator 
Javascript :: react native counter 
Javascript :: js + before variable 
Javascript :: checkbox jquery checked 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =