Recently, I used PHP to build an HTML5 website for online streaming of movies/TV series. I used PHP’s curl for real-time crawling. I encountered a problem with JS encryption, so Google solved it, and I came up with this article. Summarize.
一波Advertising
Personal homepage: www.linganmin.cn
Film station address: www.ifilm.ltd
Let’s talk about js based on crypto-js Encryption
CryptoJS is an encryption class library written purely in javascript. Its GitHub warehouse address is github.com/brix/crypt...
We need it when using it QuoteThis js file, for the convenience I quoted the link on the CDN
The code
<script src="cdn.bootcss.com/crypto-js/3.1.9/crypto-js.js"></script> <script> var data = "en2JprK0nMyYgbd6dQO0O0OO0O0O" // 需要加密的字符串 var key_base="contentWindowHig"; // 加密秘钥的基值 var iv_base="contentDocuments"; // 加密所需iv基值 /** * 定义加密函数 * @param {[type]} a [形参,需要加密的值] * @return {[type]} [加密后的值] */ var get=function(a){ var key_hash=CryptoJS.MD5(key_base); var key=CryptoJS.enc.Utf8.parse(key_hash); var iv=CryptoJS.enc.Utf8.parse(iv_base); var res=CryptoJS.AES.encrypt(a,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding}); return res.toString() } console.log(get(data)) // tPYJv39iEbdFD/UqNejyvkLG8ATdifyfE+BDeld2jWk= </script>
For The elegance of the article, php will use the same variable naming as js
Up code
// 定义变量 $data = "en2JprK0nMyYgbd6dQO0O0OO0O0O"; $key_base = "contentWindowHig"; $iv_base = "contentDocuments"; // 加密前处理 $key = md5('contentWindowHig'); $iv = $iv_base; // 加密 $cryptText = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv); $res = base64_encode($cryptText); // 解密 $cryptText = base64_decode($res); $decode = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cryptText, MCRYPT_MODE_CBC, $iv);
[Related recommendations]
1. Special Recommended : "php Programmer Toolbox" V0.1 version download
2. Free js online video tutorial
3. php.cn Dugu Jiujian (3) - JavaScript video tutorial
The above is the detailed content of Share an example of a problem based on crypto-js encryption. For more information, please follow other related articles on the PHP Chinese website!