当使用AES加解密的时候报了这个错误

原因是AES的key字节长度不对

看源码

// NewCipher creates and returns a new cipher.Block.
// The key argument should be the AES key,
// either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256.
func NewCipher(key []byte) (cipher.Block, error) {
    k := len(key)
    switch k {
    default:
        return nil, KeySizeError(k)
    case 16, 24, 32:
        break
    }
    return newCipher(key)
}

只允许16、24、32字节长度

所以把key设置成16字节长度就ok了,英文等字符,一个字符一个字节

相关文章:

  • 2021-05-07
  • 2021-12-21
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-10-07
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案