Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
5cfaa7e7
Commit
5cfaa7e7
authored
Oct 14, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
ee01ac9a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
center-manage/app/base/test.js
+33
-0
No files found.
center-manage/app/base/test.js
View file @
5cfaa7e7
const
CryptoJS
=
require
(
"crypto-js"
);
let
u
=
{
"id"
:
12
,
"nickName"
:
"好好学习"
,
"mobile"
:
"13381139519"
,
"isAdmin"
:
false
}
var
str
=
JSON
.
stringify
(
u
);
// 密钥 16 位
var
key
=
'dc35d3a0bd6641d891d3233b5286225a'
;
// 初始向量 initial vector 16 位
var
iv
=
'92bcc33e807d43fc8265ee5210e37923'
;
// key 和 iv 可以一致
key
=
CryptoJS
.
enc
.
Utf8
.
parse
(
key
);
iv
=
CryptoJS
.
enc
.
Utf8
.
parse
(
iv
);
var
encrypted
=
CryptoJS
.
AES
.
encrypt
(
str
,
key
,
{
iv
:
iv
,
mode
:
CryptoJS
.
mode
.
CBC
,
padding
:
CryptoJS
.
pad
.
Pkcs7
});
// 转换为字符串
encrypted
=
encrypted
.
toString
();
console
.
log
(
"加密串"
,
encrypted
)
console
.
log
(
"加密串"
,
encodeURIComponent
(
encrypted
))
// mode 支持 CBC、CFB、CTR、ECB、OFB, 默认 CBC
// padding 支持 Pkcs7、AnsiX923、Iso10126
// NoPadding、ZeroPadding, 默认 Pkcs7, 即 Pkcs5
// 解密
var
decrypted
=
CryptoJS
.
AES
.
decrypt
(
encrypted
,
key
,
{
iv
:
iv
,
mode
:
CryptoJS
.
mode
.
CBC
,
padding
:
CryptoJS
.
pad
.
Pkcs7
});
decrypted
=
CryptoJS
.
enc
.
Utf8
.
stringify
(
decrypted
);
console
.
log
(
"解密串"
,
decrypted
)
// var a=[1,2]
// var b=[3,4]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment