• crypto加密


    /* hash.js */
        var crypto = require('crypto');
    module.exports = function(){
         this.encode = function(){
              var algorithm  = arguments[0] ? arguments[0] : ''
            , enstring   = arguments[1] ? arguments[1] : ''
            , returnType = arguments[2] ? arguments[2] : '';
          if( algorithm ){
               var hash = crypto.createHash(algorithm);
               hash.update(enstring);
               return hash.digest(returnType);
          }
          console.log('Please input encryption param');
     }
    }
     
    /* target.js */
    module.exports = function(){
            this.encode = function(){}
            this.decode = function(){}
    }
     
    /* adapter.js */
     
    var util = require('util'),
        Target = require('./target');
     
    function Adapter(){
            Target.call(this);
            this.encode = function(){
                    var encodeModule = arguments[0] ? arguments[0] : null
                      , algorithm    = arguments[1] ? arguments[1] : ''  
                      , enstring     = arguments[2] ? arguments[2] : ''
                      , returnType   = arguments[3] ? arguments[3] : ''
                      ,AdapteeClass = require("./" + encodeModule)
                      ,adapteeObj = new AdapteeClass();
                      return adapteeObj.encode(algorithm, enstring, returnType, encodeKey, encodeType);
            }
    }
     
    util.inherits(Adapter,Target);
    module.exports = Adapter;
     
    /* test.js */
    var AdapterClass = require('./adapter');
    var Adapter = new AdapterClass();
    var hashEncodeStr = Adapter.encode('hash', 'md5', 'yuejide', 'hex');
    console.log(hashEncodeStr);
     
    var http = require('http');
    var crypto = require('crypto')
    http.createServer(function(req,res){
     res.writeHead(200, {'Content-Type' : 'text/html'});
     var md5 = crypto.createHash('md5');
     var passwd = md5.update('admin').digest('hex');
     res.end(passwd);
    }).listen(8888);
  • 相关阅读:
    C++程序代写实现HashSet class
    EL表达式
    Hibernate的事务管理
    ThreadLocal理解
    SOA框架
    JVM垃圾回收机制
    Htpp通讯协议详解
    Android模拟器使用SD卡
    android 开发-HttpClient状态码定义
    android 开发-文件存储之读写sdcard
  • 原文地址:https://www.cnblogs.com/gide/p/4448891.html
Copyright © 2020-2023  润新知