Decrypt not handle illegal string error
JiajunDou opened this issue · comments
Hello,
I encountered an issue with the following code:
func Decode(s string) (string, error) {
cipher := dongle.NewCipher()
cipher.SetMode(dongle.CBC) // CBC、CFB、OFB、CTR、ECB
cipher.SetPadding(dongle.PKCS7) // No、Zero、PKCS5、PKCS7
cipher.SetKey(c.AUTH_KEY) // key must be 16, 24 or 32 bytes
cipher.SetIV(c.IV_KEY)
e := dongle.Decode.FromString(s).ByBase62()
if e.Error != nil {
return "", e.Error
}
raw := e.ToBytes()
f := dongle.Decrypt.FromRawBytes(raw).ByAes(cipher)
if f.Error != nil {
return "", f.Error
}
return f.ToString(), nil
}
_, mustError := Decode("123")
if mustError != nil {
fmt.Println(mustError.Error())
}
golang version: 1.19
dongle version: 0.2.0
I expected to get:
Error.Error()
But I actually get:
(*cbcDecrypter).CryptBlocks: panic("crypto/cipher: input not full blocks")
go/pkg/mod/github.com/golang-module/dongle@v0.2.0/cipher.go:126 (0xddbec1)
Thanks!
Fixed in v0.2.1