adding check to the key length

In reference to #6722, I humbly submit my first PR.