Comments (1)
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-crypto-cli.