zoukankan      html  css  js  c++  java
  • Nodejs加密php解密

    var crypto = require('crypto');
    
    function decode(cryptkey, iv, secretdata) {
        var
        decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
        decoded  = decipher.update(secretdata, 'base64', 'utf8');
       
        decoded += decipher.final( 'utf8' );
        return decoded;
    }
    
    function encode(cryptkey, iv, cleardata) {
        var
        encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
        encoded  = encipher.update(cleardata, 'utf8', 'base64');
    
        encoded += encipher.final( 'base64' );
        return encoded;
    }
    
    var
    cryptkey   = crypto.createHash('sha256').update('__tazai_wolf__key').digest(),
    iv         = '1234567890000000',
    buf        = "TALK:创建房间页面。点击Creat room。怎么没反应?...",
    enc        = encode( cryptkey, iv, buf );
    
    var dec        = decode(cryptkey, iv, enc);
    
    function b64enc(data) {
        var b   = new Buffer(data, 'binary');
        return b.toString('base64');
    }
    
    console.warn("Encoded length: ", enc);
    console.warn("Decoded all: " + dec);
    
    <?php
    function decode($cryptkey, $iv, $secretdata){
        return openssl_decrypt($secretdata,'aes-256-cbc',$cryptkey,false,$iv);
    }
    function encode($cryptkey, $iv, $secretdata){
        return openssl_encrypt($secretdata,'aes-256-cbc',$cryptkey,false,$iv);
    }
    $cryptkey = hash('sha256','__tazai_wolf__key',true);
    $iv = '1234567890000000';
    $buf = "Hello World";
    
    $enc = encode($cryptkey,$iv,$buf);
    $dec = decode($cryptkey, $iv, $enc);
    
    echo "Encoded length: ",$enc,"
    ";
    echo "Decoded all: ",$dec,"
    ";
    

      

  • 相关阅读:
    SpringBoot配置文件
    SpringBoot基础开发流程
    day06-01数字类型、数字类型的转换
    特有的循环结构(for-else、while-else)——Python篇
    分支、循环——Python基础篇
    循环关键字——Python篇
    另类三目运算符——Python篇
    原码、反码以及补码
    Python运算符
    Python变量
  • 原文地址:https://www.cnblogs.com/adtuu/p/4688270.html
Copyright © 2011-2022 走看看