wie zu verwenden CryptoJS in javascript

Ich verwendet CryptoJS statt nodejs Krypto-Modul, da ich nur die nativen JavaScript,aber manche codes nicht funktionieren kann:

function aesEncrypt(text, secKey) {
  const _text = text
  const lv = new Buffer('0102030405060708', 'binary')
  const _secKey = new Buffer(secKey, 'binary')
  const cipher = crypto.createCipheriv('AES-128-CBC', _secKey, lv)
  let encrypted = cipher.update(_text, 'utf8', 'base64')
  encrypted += cipher.final('base64')
  return encrypted
}

So, wie soll ich ändern Sie diese codes?

  • aber manche codes nicht funktionieren kann. was nicht funktioniert?
  • Ich erstelle crypto mit: var crypto = CryptoJS(); , dann ist es ein Fehler, dass CryptoJS ist keine Funktion, also wie soll ich das überschreiben der code oben?
  • Haben Sie den code?
  • Ich möchte nur zu verwenden crypto mit nativen javascript-in eine statische web-Projekt, nicht in nodejs.Also ich benutze github.com/brix/crypto-js, anstelle von Krypto-Modul.
  • Ja, das beantwortet nicht meine Frage. Bitte liefern Sie genügend Ihre HTML-header.
  • <script src="cryptojs/core.js"></script> <script src="cryptojs/md5.js"></script> <script src="cryptojs/evpkdf.js"></script> <script src="cryptojs/enc-base64.js"></script> <script src="cryptojs/cipher-core.js"></script> <script src="cryptojs/aes.js"></script> <script src="cryptojs/hmac.js"></script> <script src="cryptojs/sha1.js"></script> <script src="cryptojs/sha256.js"></script> <script type="text/javascript" src="index.js"></script>

InformationsquelleAutor zhaowweny | 2018-06-23
Schreibe einen Kommentar