Encoding validation

Validate the encoding before converting it.