标签:encode str pen ecb 代码 ssl crypto console decrypt
npm install crypto-js
b. 代码:
var CryptoJS = require("crypto-js")
// 加密
var str = ‘hello‘
var key = CryptoJS.MD5(str)
key = CryptoJS.enc.Utf8.parse(key)
var encode = CryptoJS.AES.encrypt(
str,
key,
{
mode:CryptoJS.mode.ECB
}
).toString()
console.log(encode)
// 解密
var bytes = CryptoJS.AES.decrypt(
encode,
key,
{
mode:CryptoJS.mode.ECB
}
)
var decode = bytes.toString(CryptoJS.enc.Utf8)
console.log(decode)
c. 输出:
8dfQieLNIhXyHCu+KDvlNg==
hello
[Finished in 0.5s]
<?php
// 加密
$str = ‘hello‘;
$key=md5($str);
$method = ‘AES-256-ECB‘;
$encode = openssl_encrypt($str,$method,$key,0);
echo $encode.PHP_EOL;
// 解密
$decode = openssl_decrypt($encode,$method,$key,0);
echo $decode.PHP_EOL;
b. 输出:
8dfQieLNIhXyHCu+KDvlNg==
hello
[Finished in 0.2s]
标签:encode str pen ecb 代码 ssl crypto console decrypt
原文地址:http://blog.51cto.com/12173069/2293888