Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda