@@ -21,7 +21,7 @@ func normalizeKey(key []byte) ([]byte, error) {
|
||||
case 16, 24, 32:
|
||||
return key, nil
|
||||
default:
|
||||
return nil, errors.New("AES key length must be 16, 24, or 32 bytes")
|
||||
return nil, errors.New("[Cryptography AES] AES key length must be 16, 24, or 32 bytes")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func AESGCMDecrypt(encoded string, key []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
if len(data) < gcm.NonceSize() {
|
||||
return nil, errors.New("ciphertext too short")
|
||||
return nil, errors.New("[Cryptography AES] ciphertext too short")
|
||||
}
|
||||
|
||||
nonce := data[:gcm.NonceSize()]
|
||||
@@ -92,11 +92,11 @@ func pkcs7Pad(data []byte, blockSize int) []byte {
|
||||
func pkcs7Unpad(data []byte) ([]byte, error) {
|
||||
length := len(data)
|
||||
if length == 0 {
|
||||
return nil, errors.New("invalid padding")
|
||||
return nil, errors.New("[Cryptography AES] invalid padding")
|
||||
}
|
||||
padding := int(data[length-1])
|
||||
if padding == 0 || padding > length {
|
||||
return nil, errors.New("invalid padding")
|
||||
return nil, errors.New("[Cryptography AES] invalid padding")
|
||||
}
|
||||
return data[:length-padding], nil
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func AESCBCDecrypt(encoded string, key []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
if len(data) < block.BlockSize() {
|
||||
return nil, errors.New("ciphertext too short")
|
||||
return nil, errors.New("[Cryptography AES] ciphertext too short")
|
||||
}
|
||||
|
||||
iv := data[:block.BlockSize()]
|
||||
@@ -195,7 +195,7 @@ func AESCFBDecrypt(encoded string, key []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
if len(data) < block.BlockSize() {
|
||||
return nil, errors.New("ciphertext too short")
|
||||
return nil, errors.New("[Cryptography AES] ciphertext too short")
|
||||
}
|
||||
|
||||
iv := data[:block.BlockSize()]
|
||||
|
||||
Reference in New Issue
Block a user