@@ -66,7 +66,7 @@ func DecryptECB(cipherText []byte, key []byte, padding int) ([]byte, error) {
66
66
// The length of the <key> should be either 16 or 24 bytes.
67
67
func EncryptECBTriple (plainText []byte , key []byte , padding int ) ([]byte , error ) {
68
68
if len (key ) != 16 && len (key ) != 24 {
69
- return nil , gerror .New ( "key length error" )
69
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length error" )
70
70
}
71
71
72
72
text , err := Padding (plainText , padding )
@@ -100,7 +100,7 @@ func EncryptECBTriple(plainText []byte, key []byte, padding int) ([]byte, error)
100
100
// The length of the <key> should be either 16 or 24 bytes.
101
101
func DecryptECBTriple (cipherText []byte , key []byte , padding int ) ([]byte , error ) {
102
102
if len (key ) != 16 && len (key ) != 24 {
103
- return nil , gerror .New ( "key length error" )
103
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length error" )
104
104
}
105
105
106
106
var newKey []byte
@@ -138,7 +138,7 @@ func EncryptCBC(plainText []byte, key []byte, iv []byte, padding int) ([]byte, e
138
138
}
139
139
140
140
if len (iv ) != block .BlockSize () {
141
- return nil , gerror .New ( "iv length invalid" )
141
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
142
142
}
143
143
144
144
text , err := Padding (plainText , padding )
@@ -161,7 +161,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
161
161
}
162
162
163
163
if len (iv ) != block .BlockSize () {
164
- return nil , gerror .New ( "iv length invalid" )
164
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
165
165
}
166
166
167
167
text := make ([]byte , len (cipherText ))
@@ -179,7 +179,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
179
179
// EncryptCBCTriple encrypts <plainText> using TripleDES and CBC mode.
180
180
func EncryptCBCTriple (plainText []byte , key []byte , iv []byte , padding int ) ([]byte , error ) {
181
181
if len (key ) != 16 && len (key ) != 24 {
182
- return nil , gerror .New ( "key length invalid" )
182
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length invalid" )
183
183
}
184
184
185
185
var newKey []byte
@@ -196,7 +196,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
196
196
}
197
197
198
198
if len (iv ) != block .BlockSize () {
199
- return nil , gerror .New ( "iv length invalid" )
199
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
200
200
}
201
201
202
202
text , err := Padding (plainText , padding )
@@ -214,7 +214,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
214
214
// DecryptCBCTriple decrypts <cipherText> using TripleDES and CBC mode.
215
215
func DecryptCBCTriple (cipherText []byte , key []byte , iv []byte , padding int ) ([]byte , error ) {
216
216
if len (key ) != 16 && len (key ) != 24 {
217
- return nil , gerror .New ( "key length invalid" )
217
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length invalid" )
218
218
}
219
219
220
220
var newKey []byte
@@ -231,7 +231,7 @@ func DecryptCBCTriple(cipherText []byte, key []byte, iv []byte, padding int) ([]
231
231
}
232
232
233
233
if len (iv ) != block .BlockSize () {
234
- return nil , gerror .New ( "iv length invalid" )
234
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
235
235
}
236
236
237
237
text := make ([]byte , len (cipherText ))
@@ -262,12 +262,12 @@ func Padding(text []byte, padding int) ([]byte, error) {
262
262
switch padding {
263
263
case NOPADDING :
264
264
if len (text )% 8 != 0 {
265
- return nil , gerror .New ( "text length invalid" )
265
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "text length invalid" )
266
266
}
267
267
case PKCS5PADDING :
268
268
return PaddingPKCS5 (text , 8 ), nil
269
269
default :
270
- return nil , gerror .New ( "padding type error" )
270
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "padding type error" )
271
271
}
272
272
273
273
return text , nil
@@ -277,12 +277,12 @@ func UnPadding(text []byte, padding int) ([]byte, error) {
277
277
switch padding {
278
278
case NOPADDING :
279
279
if len (text )% 8 != 0 {
280
- return nil , gerror .New ( "text length invalid" )
280
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "text length invalid" )
281
281
}
282
282
case PKCS5PADDING :
283
283
return UnPaddingPKCS5 (text ), nil
284
284
default :
285
- return nil , gerror .New ( "padding type error" )
285
+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "padding type error" )
286
286
}
287
287
return text , nil
288
288
}
0 commit comments