Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
TypeError: crypto.createCipheriv is not a function

vite+vue3 uses aes-cross to report: TypeError: crypto.createCipheriv is not a function Version: "vue": "^3.2.23", "vite": "^2.6.4", "aes-cross": "^1.0.9",

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

To get crypto working in browser, follow instructions bellow 👇

  1. Add dependencies

yarn add stream-browserify browserify-zlib events process util buffer

  1. Configure vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      process: "process/browser",
      stream: "stream-browserify",
      zlib: "browserify-zlib",
      util: 'util'
    }
  }
})

  1. Add JS to index.html
<!-- [...] -->
<div id="root"></div>

<!-- node // crypto -->
<script>window.global = window;</script>
<script type="module">
    import { Buffer } from "buffer/"; // <-- no typo here ("/")
    import process from "process";
    import EventEmitter from "events";
        
    window.Buffer = Buffer;
    window.process = process;
    window.EventEmitter = EventEmitter;
</script>
<!-- [...] -->
  1. Add imports to App.vue, and testing function

in App.vue:

import crypto from 'crypto-browserify'
import { Buffer } from 'buffer/' // <-- no typo here ("/")

// test crypto 
function crypt() {
  // Node.js program to demonstrate the    
  // crypto.createCipheriv() method
  
  const iv = crypto.randomBytes(16);
  const key = crypto.pbkdf2Sync("foobar", "salt", 1000, 32, 'sha512');
  const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
  var text = crypto.randomBytes(200)
  var ourCipherText = Buffer.concat([cipher.update(text), cipher.final()])
  console.log("ciphered text:", ourCipherText.toString('hex'))

  return ourCipherText.toString('hex');
}

[...]

Result ✅

crypto browser screencast

about 4 years ago · Juan Pablo Isaza Denunciar

0

The function crypto.createCipheriv is a node.js only function meaning it is not available in the browser like in a Vue app. You should look into SubtleCrypto which provides native web features for many encryption purposes like AES. As always, it should be noted that one should be very careful and methodical when using low-level crypto primitives, especially regarding encryption. This page provides more examples of AES encryption specifically.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda