1
- import { secret } from "./index" ;
2
- import { Algorithm } from "./lib/algorithm.enum" ;
1
+ import { Algorithm , secret } from "./index" ;
3
2
4
- describe ( "secret " , ( ) => {
3
+ describe ( "AES/CBC with IV " , ( ) => {
5
4
it ( "should return the initial input when passing encrypt to decrypt" , async ( ) => {
6
5
// GIVEN
7
6
const key = "C9HikSYQW/K+ZvRphxEuSw==" ;
8
7
const input = "Can you keep a secret?" ;
9
8
10
9
// WHEN
11
- const encrypted = await secret . encrypt ( input , key ) ;
12
- const output = await secret . decrypt ( encrypted , key ) ;
10
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128CBC ) ;
11
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128CBC ) ;
13
12
14
13
// THEN
15
14
expect ( output ) . toBe ( input ) ;
@@ -21,8 +20,8 @@ describe("secret", () => {
21
20
const input = "Can you keep a secret?" ;
22
21
23
22
// WHEN
24
- const encrypted = await secret . encrypt ( input , key ) ;
25
- const output = await secret . decrypt ( encrypted , key ) ;
23
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128CBC ) ;
24
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128CBC ) ;
26
25
27
26
// THEN
28
27
expect ( output ) . toBe ( input ) ;
@@ -34,8 +33,131 @@ describe("secret", () => {
34
33
const input = "Can you keep a secret?" ;
35
34
36
35
// WHEN
37
- const encrypted = await secret . encrypt ( input , key ) ;
38
- const output = await secret . decrypt ( encrypted , key ) ;
36
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES256CBC ) ;
37
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES256CBC ) ;
38
+
39
+ // THEN
40
+ expect ( output ) . toBe ( input ) ;
41
+ } ) ;
42
+ } ) ;
43
+
44
+ describe ( "AES/CBC without IV" , ( ) => {
45
+ it ( "should return the initial input when passing encrypt to decrypt" , async ( ) => {
46
+ // GIVEN
47
+ const key = "C9HikSYQW/K+ZvRphxEuSw==" ;
48
+ const input = "Can you keep a secret?" ;
49
+
50
+ // WHEN
51
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128CBC , false ) ;
52
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128CBC , false ) ;
53
+
54
+ // THEN
55
+ expect ( output ) . toBe ( input ) ;
56
+ } ) ;
57
+
58
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES128CBC" , async ( ) => {
59
+ // GIVEN
60
+ const key = await secret . generateKey ( Algorithm . AES128CBC ) ;
61
+ const input = "Can you keep a secret?" ;
62
+
63
+ // WHEN
64
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128CBC , false ) ;
65
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128CBC , false ) ;
66
+
67
+ // THEN
68
+ expect ( output ) . toBe ( input ) ;
69
+ } ) ;
70
+
71
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES256CBC" , async ( ) => {
72
+ // GIVEN
73
+ const key = await secret . generateKey ( Algorithm . AES256CBC ) ;
74
+ const input = "Can you keep a secret?" ;
75
+
76
+ // WHEN
77
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES256CBC , false ) ;
78
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES256CBC , false ) ;
79
+
80
+ // THEN
81
+ expect ( output ) . toBe ( input ) ;
82
+ } ) ;
83
+ } ) ;
84
+
85
+ describe ( "AES/ECB with IV" , ( ) => {
86
+ it ( "should return the initial input when passing encrypt to decrypt" , async ( ) => {
87
+ // GIVEN
88
+ const key = "C9HikSYQW/K+ZvRphxEuSw==" ;
89
+ const input = "Can you keep a secret?" ;
90
+
91
+ // WHEN
92
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128ECB ) ;
93
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128ECB ) ;
94
+
95
+ // THEN
96
+ expect ( output ) . toBe ( input ) ;
97
+ } ) ;
98
+
99
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES128ECB" , async ( ) => {
100
+ // GIVEN
101
+ const key = await secret . generateKey ( Algorithm . AES128ECB ) ;
102
+ const input = "Can you keep a secret?" ;
103
+
104
+ // WHEN
105
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128ECB ) ;
106
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128ECB ) ;
107
+
108
+ // THEN
109
+ expect ( output ) . toBe ( input ) ;
110
+ } ) ;
111
+
112
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES256ECB" , async ( ) => {
113
+ // GIVEN
114
+ const key = await secret . generateKey ( Algorithm . AES256ECB ) ;
115
+ const input = "Can you keep a secret?" ;
116
+
117
+ // WHEN
118
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES256ECB ) ;
119
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES256ECB ) ;
120
+
121
+ // THEN
122
+ expect ( output ) . toBe ( input ) ;
123
+ } ) ;
124
+ } ) ;
125
+
126
+ describe ( "AES/ECB without IV" , ( ) => {
127
+ it ( "should return the initial input when passing encrypt to decrypt" , async ( ) => {
128
+ // GIVEN
129
+ const key = "C9HikSYQW/K+ZvRphxEuSw==" ;
130
+ const input = "Can you keep a secret?" ;
131
+
132
+ // WHEN
133
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128ECB , false ) ;
134
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128ECB , false ) ;
135
+
136
+ // THEN
137
+ expect ( output ) . toBe ( input ) ;
138
+ } ) ;
139
+
140
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES128ECB" , async ( ) => {
141
+ // GIVEN
142
+ const key = await secret . generateKey ( Algorithm . AES128ECB ) ;
143
+ const input = "Can you keep a secret?" ;
144
+
145
+ // WHEN
146
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES128ECB , false ) ;
147
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES128ECB , false ) ;
148
+
149
+ // THEN
150
+ expect ( output ) . toBe ( input ) ;
151
+ } ) ;
152
+
153
+ it ( "should return the initial input when passing encrypt to decrypt with generated key for AES256ECB" , async ( ) => {
154
+ // GIVEN
155
+ const key = await secret . generateKey ( Algorithm . AES256ECB ) ;
156
+ const input = "Can you keep a secret?" ;
157
+
158
+ // WHEN
159
+ const encrypted = await secret . encrypt ( input , key , Algorithm . AES256ECB , false ) ;
160
+ const output = await secret . decrypt ( encrypted , key , Algorithm . AES256ECB , false ) ;
39
161
40
162
// THEN
41
163
expect ( output ) . toBe ( input ) ;
0 commit comments