Permalink
Browse files

Create systemUtil.js

  • Loading branch information...
1 parent 4f66f4f commit d4204ef31747e790aa56a475b050a15d1f94e391 @lenbo-ma committed Jan 30, 2013
Showing with 43 additions and 0 deletions.
  1. +43 −0 systemUtil.js
View
@@ -0,0 +1,43 @@
+/**
+ * 系统工具
+ */
+var crypto = require('crypto');
+/**
+ *
+ * @param str
+ * @param secret
+ * @return {*}
+ */
+function encrypt(str,secret) {
+ var cipher = crypto.createCipher('aes192', secret);
+ var enc = cipher.update(str,'utf8','hex');
+ enc += cipher.final('hex');
+ return enc;
+}
+/**
+ *
+ * @param str
+ * @param secret
+ * @return {*}
+ */
+function decrypt(str,secret) {
+ var decipher = crypto.createDecipher('aes192', secret);
+ var dec = decipher.update(str,'hex','utf8');
+ dec += decipher.final('utf8');
+ return dec;
+}
+/**
+ * md5加密
+ * @param str
+ * @return {*}
+ */
+function md5(str) {
+ var md5sum = crypto.createHash('md5');
+ md5sum.update(str);
+ str = md5sum.digest('hex');
+ return str;
+}
+
+exports.encrypt = encrypt;
+exports.decrypt = decrypt;
+exports.md5 = md5;

0 comments on commit d4204ef

Please sign in to comment.