Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to decrypt in browser ? #7

Open
pranaysonisoft opened this issue Jul 26, 2019 · 2 comments
Open

how to decrypt in browser ? #7

pranaysonisoft opened this issue Jul 26, 2019 · 2 comments
Labels

Comments

@pranaysonisoft
Copy link

var crypto = require('crypto');
not in browser . i try a https://github.com/brix/crypto-js in browser but

crypto-js show a message 'sorry createDecipher is not implemented yet'

@roryrjb
Copy link
Contributor

roryrjb commented Jul 27, 2019

@pranaysonisoft looks like crypto-js isn't a complete enough implementation of crypto for this to work in the browser. How about trying crypto-browserify? Although I haven't tried that.

@pranaysonisoft
Copy link
Author

i change a decrypt and encrypt function code with a crypto-js

var CryptoJS = require("crypto-js");

let encryptValue, decryptValue, encryptObject, decryptObject

const decrypt = (pw, algo, enc) => (value) => {
  // const decipher = crypto.createDecipher(algo, pw)
  //
  // return JSON.parse(decipher.update(value, enc, 'utf8') +
  //   decipher.final('utf8'))
  let bytes  = CryptoJS.AES.decrypt(value.toString(),pw);
  let plaintext = bytes.toString(CryptoJS.enc.Utf8);
  return plaintext;
}

const encrypt = (pw, algo, enc) => (value) => {
  // const cipher = crypto.createCipher(algo, pw)
  //
  // var final = cipher.update(JSON.stringify(value), 'utf8', enc) + cipher.final(enc);

  let ciphertext = CryptoJS.AES.encrypt(JSON.stringify(value), pw);
  let final_text = ciphertext.toString();

  //return final;
   return final_text;
}

@roryrjb roryrjb closed this as completed Apr 3, 2020
@roryrjb roryrjb reopened this Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants