Created
April 20, 2018 02:21
-
-
Save bbstilson/fd8d81d758731f354a9d1223ef45b132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encrypt(text, password) { | |
const initVect = crypto.randomBytes(16); | |
const key = getCipherKey(password); | |
const cipher = createCipheriv('aes256', key, initVect); | |
const cipherText = cipher.update(text).digest(); | |
return initVect + ciphertext; | |
} | |
encrypt('hello', 'mygr8password'); |
Hey Cully. "bad" is meant more as "not ideal". This function requires all the data be in memory as opposed to being processed through a stream. I go into more details in the accompanying blog post here. Grep for "Generating an initialization vector" to jump straight to the context for this code snippet.
That's helpful, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In what way is this bad?