1
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func AESCBCEncpryt(data, aesKey, iv []byte) (encryptedData []byte, err error) {
|
||||
@@ -24,7 +23,6 @@ func AESCBCDecpryt(encryptedData, aesKey, iv []byte) (decryptedData []byte, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(c.BlockSize(), len(encryptedData))
|
||||
cfbdec := cipher.NewCBCDecrypter(c, iv[:c.BlockSize()])
|
||||
decryptedData = make([]byte, len(encryptedData))
|
||||
cfbdec.CryptBlocks(decryptedData, encryptedData)
|
||||
@@ -33,19 +31,6 @@ func AESCBCDecpryt(encryptedData, aesKey, iv []byte) (decryptedData []byte, err
|
||||
return decryptedData, nil
|
||||
}
|
||||
|
||||
func PKCSUnPadding(originData []byte) []byte {
|
||||
length := len(originData)
|
||||
unpadding := int(originData[length-1])
|
||||
originData = originData[:(length - unpadding)]
|
||||
return originData
|
||||
}
|
||||
|
||||
func PKCSPadding(ciphertext []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(ciphertext)%blockSize
|
||||
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||
return append(ciphertext, padtext...)
|
||||
}
|
||||
|
||||
// AESCBC16Decrypt 抖音十六位解密
|
||||
func AESCBC16Decrypt(key, iv, src []byte) ([]byte, error) {
|
||||
decrypted := make([]byte, len(src))
|
||||
@@ -59,3 +44,16 @@ func AESCBC16Decrypt(key, iv, src []byte) ([]byte, error) {
|
||||
aesDecrypt.CryptBlocks(decrypted, src)
|
||||
return decrypted[:len(decrypted)-int(decrypted[len(decrypted)-1])], err
|
||||
}
|
||||
|
||||
func PKCSUnPadding(originData []byte) []byte {
|
||||
length := len(originData)
|
||||
unpadding := int(originData[length-1])
|
||||
originData = originData[:(length - unpadding)]
|
||||
return originData
|
||||
}
|
||||
|
||||
func PKCSPadding(ciphertext []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(ciphertext)%blockSize
|
||||
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||
return append(ciphertext, padtext...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user