File tree Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const secret = process.env.secret;
6
6
7
7
const clientId = "c16b80e7b58a5a007157" ;
8
8
const algorithm = "aes-256-ctr" ;
9
- const iv = crypto . randomBytes ( 16 ) ;
9
+ const iv = crypto . randomBytes ( 16 ) . toString ( "hex" ) ;
10
10
11
11
const db = [
12
12
{
@@ -19,21 +19,18 @@ function encrypt(text) {
19
19
20
20
const encrypted = Buffer . concat ( [ cipher . update ( text ) , cipher . final ( ) ] ) ;
21
21
22
- return {
23
- iv : iv . toString ( "hex" ) ,
24
- content : encrypted . toString ( "hex" ) ,
25
- } ;
22
+ return encrypted . toString ( "hex" ) ;
26
23
}
27
24
28
- function decrypt ( hash ) {
25
+ function decrypt ( content ) {
29
26
const decipher = crypto . createDecipheriv (
30
27
algorithm ,
31
28
secret . slice ( 0 , 32 ) ,
32
- Buffer . from ( hash , iv , "hex" )
29
+ Buffer . from ( iv , "hex" )
33
30
) ;
34
31
35
32
const decrpyted = Buffer . concat ( [
36
- decipher . update ( Buffer . from ( hash . content , "hex" ) ) ,
33
+ decipher . update ( Buffer . from ( content , "hex" ) ) ,
37
34
decipher . final ( ) ,
38
35
] ) ;
39
36
You can’t perform that action at this time.
0 commit comments