File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ class AESDecrypt extends Operation {
112
112
run ( input , args ) {
113
113
const key = Utils . convertToByteString ( args [ 0 ] . string , args [ 0 ] . option ) ,
114
114
iv = Utils . convertToByteString ( args [ 1 ] . string , args [ 1 ] . option ) ,
115
- mode = args [ 2 ] . substring ( 0 , 3 ) ,
115
+ mode = args [ 2 ] . split ( "/" ) [ 0 ] ,
116
116
noPadding = args [ 2 ] . endsWith ( "NoPadding" ) ,
117
117
inputType = args [ 3 ] ,
118
118
outputType = args [ 4 ] ,
Original file line number Diff line number Diff line change @@ -66,6 +66,14 @@ class AESEncrypt extends Operation {
66
66
{
67
67
name : "ECB" ,
68
68
off : [ 5 ]
69
+ } ,
70
+ {
71
+ name : "CBC/NoPadding" ,
72
+ off : [ 5 ]
73
+ } ,
74
+ {
75
+ name : "ECB/NoPadding" ,
76
+ off : [ 5 ]
69
77
}
70
78
]
71
79
} ,
@@ -98,7 +106,8 @@ class AESEncrypt extends Operation {
98
106
run ( input , args ) {
99
107
const key = Utils . convertToByteString ( args [ 0 ] . string , args [ 0 ] . option ) ,
100
108
iv = Utils . convertToByteString ( args [ 1 ] . string , args [ 1 ] . option ) ,
101
- mode = args [ 2 ] ,
109
+ mode = args [ 2 ] . split ( "/" ) [ 0 ] ,
110
+ noPadding = args [ 2 ] . endsWith ( "NoPadding" ) ,
102
111
inputType = args [ 3 ] ,
103
112
outputType = args [ 4 ] ,
104
113
aad = Utils . convertToByteString ( args [ 5 ] . string , args [ 5 ] . option ) ;
@@ -114,11 +123,20 @@ The following algorithms will be used based on the size of the key:
114
123
115
124
input = Utils . convertToByteString ( input , inputType ) ;
116
125
126
+ // Handle NoPadding modes
127
+ if ( noPadding && input . length % 16 !== 0 ) {
128
+ throw new OperationError ( "Input length must be a multiple of 16 bytes for NoPadding modes." ) ;
129
+ }
117
130
const cipher = forge . cipher . createCipher ( "AES-" + mode , key ) ;
118
131
cipher . start ( {
119
132
iv : iv ,
120
133
additionalData : mode === "GCM" ? aad : undefined
121
134
} ) ;
135
+ if ( noPadding ) {
136
+ cipher . mode . pad = function ( output , options ) {
137
+ return true ;
138
+ } ;
139
+ }
122
140
cipher . update ( forge . util . createBuffer ( input ) ) ;
123
141
cipher . finish ( ) ;
124
142
You can’t perform that action at this time.
0 commit comments