Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DoorLock
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
felix
DoorLock
Commits
88c74ce6
Commit
88c74ce6
authored
Oct 27, 2017
by
朱建香
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1027
parent
399e5f0f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
dev/src/public/crypto.js
+39
-0
No files found.
dev/src/public/crypto.js
0 → 100644
View file @
88c74ce6
/**
* @class
* crypto
*/
import
CryptoJS
from
"crypto-js"
;
import
md5
from
"md5"
;
class
crypto
{
static
MD5
(
string
){
console
.
log
(
string
);
return
md5
(
string
);
}
static
enkey
(
string
){
let
key
=
this
.
MD5
(
string
).
substr
(
8
,
16
);
let
iv
=
this
.
MD5
(
key
).
substr
(
8
,
16
);
let
keyIv
=
{
"key"
:
key
,
"iv"
:
iv
}
return
keyIv
;
}
static
encode
(
msg
,
keyIv
){
let
message
=
JSON
.
stringify
(
msg
);
let
key
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyIv
.
key
);
let
iv
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyIv
.
iv
);
let
code
=
CryptoJS
.
AES
.
encrypt
(
message
,
key
,
{
iv
:
iv
},{
mode
:
CryptoJS
.
mode
.
CBC
,
padding
:
CryptoJS
.
pad
.
nopadding
});
return
code
.
toString
();
}
static
decode
(
code
,
keyIv
){
let
key
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyIv
.
key
);
let
iv
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyIv
.
iv
);;
let
decryptedData
=
CryptoJS
.
AES
.
decrypt
(
code
,
key
,
{
iv
:
iv
},{
mode
:
CryptoJS
.
mode
.
CBC
,
padding
:
CryptoJS
.
pad
.
nopadding
});
return
JSON
.
parse
(
decryptedData
.
toString
(
CryptoJS
.
enc
.
Utf8
));
}
}
export
default
crypto
;
\ No newline at end of file
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