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);
  • 相关阅读:
    is 和 == 区别@编码
    python字典
    python的简介
    初始python3
    初始python2
    初始python1
    Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
    Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things
    2019ICPC区域赛(银川)总结
    Educational Codeforces Round 74 (Rated for Div. 2) D. AB-string
  • 原文地址:https://www.cnblogs.com/yulei126/p/6786082.html
Copyright © 2011-2022 走看看