惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
J
Java Code Geeks
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 三生石上(FineUI控件)
Attack and Defense Labs
Attack and Defense Labs
AI
AI
The Cloudflare Blog
T
Tailwind CSS Blog
S
Schneier on Security
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
V2EX - 技术
V2EX - 技术
S
Securelist
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Help Net Security
Help Net Security
C
Cisco Blogs
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 今夜太冷

GPG(GnuPG)入门 Session variables lost after the call of Response.Redirect method c++中POD类型和non-POD类型 关于c++ template的branching和Recursion的一段很好的描述 How do I remove a particular element from an array in JavaScript? Get the client's IP address in socket.io C++ delegate的几种方法 MFC更换窗口图标 boost::make_function_output_iterator报错: C4996 How to copy the contents of std::vector to c-style static array,safely? std::vector push_back报错Access violation Structured Exception Handling Catch a Memory Access Violation in C++ Windows上的字符转换之CP_ACP和CP_OEMCP Initialize a vector in C++ (5 different ways) MFC中使用ATL报错:error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C++ WINDOWS下 wchar_t *和char * 相互转化总结篇 VS2008 编译出错 fatal error C1859: unexpected precompiled header error, simply rerunning the compiler might fix this problem 解析XML出错,无法创建DOMDocument对象
前端 使用 crypto-js 对数据进行对称加密
今夜太冷 · 2018-09-05 · via 博客园 - 今夜太冷

From:  https://www.cnblogs.com/CyLee/p/7216988.html

传送门:

# crypto-js github
https://github.com/brix/crypto-js

demo1:

复制代码

// 加载核心加密库
var CryptoJS = require("crypto-js");
// 加载des算法
var tripledes = require("crypto-js/tripledes");
// 开始加密,并且返回密文
var ciphertext  = tripledes.encrypt("fuckyou", '123').toString();
// 解密
var plaintext  = tripledes.decrypt(ciphertext, '123').toString(CryptoJS.enc.Utf8)
// 输出密文和解密后的内容
console.log(ciphertext, plaintext)

复制代码

demo2:

复制代码

// 加载核心加密库
var CryptoJS = require("crypto-js");

function encrypt (message, key) {
    var keyHex = CryptoJS.enc.Utf8.parse(key);
     var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return {
        key: keyHex,
        value: encrypted.toString()
    }
}

function decrypt (message, key) {
    var plaintext = CryptoJS.DES.decrypt(message, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    })
    return plaintext.toString(CryptoJS.enc.Utf8)
}

var a = encrypt('mssage123', '123');
var b = decrypt(a.value, a.key);

console.log(a.value.length)