Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added crypto utility, modified user module to encrypt passwords in mo…

…ngodb. You will need to drop current mongodb schema as users will be invalid.
  • Loading branch information...
commit b7dafe6d920545a32859f425a256f84821b8b284 1 parent ff0bec8
@cliftonc authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 utils/crypto.js
View
29 utils/crypto.js
@@ -0,0 +1,29 @@
+var crypto = require("crypto");
+
+/**
+ * Export simple encrypt / decrypt functions
+ */
+module.exports = exports = {
+ decrypt: decrypt,
+ encrypt: encrypt
+}
+
+/**
+ * Decrypt a string
+ */
+function decrypt(string,key) {
+ var decipher = crypto.createDecipher('aes-256-cbc',key)
+ var dec = decipher.update(string,'hex','utf8')
+ dec += decipher.final('utf8')
+ return dec;
+}
+
+/**
+ * Encrypt a string
+ */
+function encrypt(string,key) {
+ var cipher = crypto.createCipher('aes-256-cbc',key)
+ var crypted = cipher.update(string,'utf8','hex')
+ crypted += cipher.final('hex')
+ return crypted;
+}

0 comments on commit b7dafe6

Please sign in to comment.
Something went wrong with that request. Please try again.