diff --git a/chachapoly/chachapoly.go b/chachapoly/chachapoly.go index dcd3437..3f26db8 100644 --- a/chachapoly/chachapoly.go +++ b/chachapoly/chachapoly.go @@ -28,6 +28,9 @@ func Encrypt(plaintext []byte, key []byte) ([]byte, error) { // Decrypt decrypts data using ChaCha20-Poly1305. func Decrypt(ciphertext []byte, key []byte) ([]byte, error) { + if len(key) != chacha20poly1305.KeySize { + return nil, fmt.Errorf("invalid key size: got %d bytes, want %d bytes", len(key), chacha20poly1305.KeySize) + } aead, err := chacha20poly1305.NewX(key) if err != nil { return nil, err