mirror of
https://github.com/moonD4rk/HackBrowserData
synced 2025-02-21 13:06:54 +00:00
fix: add block size check, Close #120
This commit is contained in:
parent
0dc28a077f
commit
13c92b0a2e
@ -179,14 +179,17 @@ func aes128CBCDecrypt(key, iv, encryptPass []byte) ([]byte, error) {
|
||||
dst := make([]byte, encryptLen)
|
||||
mode := cipher.NewCBCDecrypter(block, iv)
|
||||
mode.CryptBlocks(dst, encryptPass)
|
||||
dst = PKCS5UnPadding(dst)
|
||||
dst = pkcs5UnPadding(dst, block.BlockSize())
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func PKCS5UnPadding(src []byte) []byte {
|
||||
length := len(src)
|
||||
unpad := int(src[length-1])
|
||||
return src[:(length - unpad)]
|
||||
func pkcs5UnPadding(src []byte, blockSize int) []byte {
|
||||
n := len(src)
|
||||
paddingNum := int(src[n-1])
|
||||
if n < paddingNum || paddingNum > blockSize {
|
||||
return src
|
||||
}
|
||||
return src[:n-paddingNum]
|
||||
}
|
||||
|
||||
// des3Decrypt use for decrypter firefox PBE
|
||||
@ -198,7 +201,7 @@ func des3Decrypt(key, iv []byte, src []byte) ([]byte, error) {
|
||||
blockMode := cipher.NewCBCDecrypter(block, iv)
|
||||
sq := make([]byte, len(src))
|
||||
blockMode.CryptBlocks(sq, src)
|
||||
return sq, nil
|
||||
return pkcs5UnPadding(sq, block.BlockSize()), nil
|
||||
}
|
||||
|
||||
func paddingZero(s []byte, l int) []byte {
|
||||
|
Loading…
Reference in New Issue
Block a user