fix(des):修复DES加密时出现的密文字节数组长度不足的情况。
This commit is contained in:
parent
5e284f320d
commit
185f1f3195
|
@ -41,8 +41,8 @@ func Encrypt(data []byte, key []byte, padding encryption.PaddingMode, keyGenerat
|
||||||
}
|
}
|
||||||
|
|
||||||
iv := keyBytes[:]
|
iv := keyBytes[:]
|
||||||
cipherText := make([]byte, len(data))
|
|
||||||
plainText := encryption.Padding(data, block.BlockSize(), padding)
|
plainText := encryption.Padding(data, block.BlockSize(), padding)
|
||||||
|
cipherText := make([]byte, len(plainText))
|
||||||
mode := cipher.NewCBCEncrypter(block, iv)
|
mode := cipher.NewCBCEncrypter(block, iv)
|
||||||
mode.CryptBlocks(cipherText, plainText)
|
mode.CryptBlocks(cipherText, plainText)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,9 @@ func Unpadding(data []byte, padding ...PaddingMode) []byte {
|
||||||
case PKCS7Padding:
|
case PKCS7Padding:
|
||||||
length := len(data)
|
length := len(data)
|
||||||
unpadding := int(data[length-1])
|
unpadding := int(data[length-1])
|
||||||
|
if length-unpadding < 0 {
|
||||||
|
return make([]byte, 0)
|
||||||
|
}
|
||||||
return data[:(length - unpadding)]
|
return data[:(length - unpadding)]
|
||||||
case NoPadding:
|
case NoPadding:
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user