GithubHelp home page GithubHelp logo

Comments (1)

lutsifer avatar lutsifer commented on May 30, 2024

I suspect the problem to be inside the string encoding part. I tried to alter it to base64:

function encrypt(encKey, content) { let iv_length = 16; let iv = crypto.randomBytes(iv_length); let cipher = crypto.createCipheriv('AES-256-CBC', Buffer.from(encKey), iv); let encrypted = cipher.update(content); encrypted = Buffer.concat([encrypted, cipher.final()]); return iv.toString('base64') + ':' + encrypted.toString('base64'); }

function decrypt(encKey, content){ let textParts = content.split(':'); let iv = Buffer.from(textParts.shift(), 'base64'); let encryptedContent = Buffer.from(textParts.join(':'), 'base64'); let decipher = crypto.createDecipheriv('AES-256-CBC', Buffer.from(encKey), iv); let decrypted = decipher.update(encryptedContent); decrypted = Buffer.concat([decrypted, decipher.final()]); return decrypted.toString(); }
It works well with text files etc, but it fails on jpg as before...

from node-crypto-cli.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.