fix aes unpk
This commit is contained in:
parent
87ea785119
commit
31a80eb904
|
@ -28,6 +28,9 @@ func New() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateTokenAes(id uint, identity, client, role string, extend map[string]string) (string, error) {
|
func GenerateTokenAes(id uint, identity, client, role string, extend map[string]string) (string, error) {
|
||||||
|
if (JwtSecretLen == 16 || JwtSecretLen == 24 || JwtSecretLen == 32) == false {
|
||||||
|
return "", errors.New("JwtSecret lenght must 16/24/32.")
|
||||||
|
}
|
||||||
expireTime := time.Now().Add(vars.JwtExpireDay)
|
expireTime := time.Now().Add(vars.JwtExpireDay)
|
||||||
claims := types.JwtClaims{
|
claims := types.JwtClaims{
|
||||||
ID: id,
|
ID: id,
|
||||||
|
@ -51,9 +54,7 @@ func GenerateTokenAes(id uint, identity, client, role string, extend map[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func AesEncryptCBC(plan []byte) (string, error) {
|
func AesEncryptCBC(plan []byte) (string, error) {
|
||||||
if (JwtSecretLen == 16 || JwtSecretLen == 24 || JwtSecretLen == 32) == false {
|
|
||||||
return "", errors.New("JwtSecret lenght must 16/24/32.")
|
|
||||||
}
|
|
||||||
// 分组秘钥
|
// 分组秘钥
|
||||||
// NewCipher该函数限制了输入k的长度必须为16, 24或者32
|
// NewCipher该函数限制了输入k的长度必须为16, 24或者32
|
||||||
block, _ := aes.NewCipher(JwtSecret)
|
block, _ := aes.NewCipher(JwtSecret)
|
||||||
|
@ -121,6 +122,10 @@ func PKCS7UnPadding(origData []byte, blocksize int) []byte {
|
||||||
|
|
||||||
length := len(origData)
|
length := len(origData)
|
||||||
unpadding := int(origData[length-1])
|
unpadding := int(origData[length-1])
|
||||||
|
|
||||||
|
if length-unpadding <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return origData[:(length - unpadding)]
|
return origData[:(length - unpadding)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue