首页 > 代码库 > crypto加密
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);
crypto加密
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。