zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    创建spring自定义注解进行自动装配
    springmvc接收到的json数据乱码
    hibernate自动创建表失败
    Symfony2学习笔记之HTTP Cache
    EF4+Repository+UnitOfWork 代码摘录
    Symfony2学习笔记之表单
    Symfony2 学习笔记之内部构件
    Symfony2学习笔记之数据校验
    Symfony2 学习笔记之插件格式
    Symfony2学习笔记之数据库操作
  • 原文地址:https://www.cnblogs.com/gide/p/4448891.html
Copyright © 2011-2022 走看看