zoukankan      html  css  js  c++  java
  • 对称加密算法

    http://www.cnblogs.com/happyhippy/archive/2006/12/23/601353.html

      //参数的意思

    1. test_des({  
    2.     alg: 'des-ede3-cbc',   //进程  
    3.     autoPad: true, 
    4.     key: '0123456789abcd0123456789',  //钥匙
    5.     plaintext: '1234567812345678',  //明码文本
    6.     iv: '12345678'  //初始化向量
    7. })  

    http://qson.iteye.com/blog/2041133

    nodejs  对称加密

    1. var assert = require('assert');  
    2. var crypto = require('crypto');  
    3.   
    4. function test_des(param) {  
    5.     var key = new Buffer(param.key);  
    6.     var iv = new Buffer(param.iv ? param.iv : 0)  
    7.     var plaintext = param.plaintext  
    8.     var alg = param.alg  
    9.     var autoPad = param.autoPad  
    10.       
    11.     //encrypt  
    12.     var cipher = crypto.createCipheriv(alg, key, iv);  
    13.     cipher.setAutoPadding(autoPad)  //default true  
    14.     var ciph = cipher.update(plaintext, 'utf8', 'hex');  
    15.     ciph += cipher.final('hex');  
    16.     console.log(alg, ciph)  
    17.   
    18.     //decrypt  
    19.     var decipher = crypto.createDecipheriv(alg, key, iv);  
    20.     cipher.setAutoPadding(autoPad)  
    21.     var txt = decipher.update(ciph, 'hex', 'utf8');  
    22.     txt += decipher.final('utf8');      
    23.     assert.equal(txt, plaintext, 'fail');  
    24. }  
    25.   
    26. test_des({  
    27.     alg: 'des-ecb',  
    28.     autoPad: true,  
    29.     key: '01234567',  
    30.     plaintext: '1234567812345678',  
    31.     iv: null  
    32. })  
    33.   
    34. test_des({  
    35.     alg: 'des-cbc',  
    36.     autoPad: true,  
    37.     key: '01234567',  
    38.     plaintext: '1234567812345678',  
    39.     iv: '12345678'  
    40. })  
    41.   
    42. test_des({  
    43.     alg: 'des-ede3',    //3des-ecb  
    44.     autoPad: true,  
    45.     key: '0123456789abcd0123456789',  
    46.     plaintext: '1234567812345678',  
    47.     iv: null  
    48. })  
    49.   
    50. test_des({  
    51.     alg: 'des-ede3-cbc',    //3des-cbc  
    52.     autoPad: true,  
    53.     key: '0123456789abcd0123456789',  
    54.     plaintext: '1234567812345678',  
    55.     iv: '12345678'  
    56. })  
  • 相关阅读:
    ✍08 docker安装问题
    axios跨域post请求中,后台把整个body对象当成了请求参数的键
    nginx运行vue项目,并对后端做负载均衡
    Linux安装nginx
    vue项目运行后无IP,本地网址显示为 http://[C:WindowsSystem32driversetc]:8080/
    Notion ---- 侧边栏目录插件
    工作笔记1-时间字段序列化
    web测试方法总结
    Hive构成及工作原理简介
    oracle 之表分区详解
  • 原文地址:https://www.cnblogs.com/benpaodexiaopangzi/p/6247682.html
Copyright © 2011-2022 走看看