# Restricting output of key derivation function

Are there any suitable key derivation functions that allow the output to have certain constraints applied to them?

I know you can choose a length in some functions (HKDF for example), but what about restricting the output to conform to a subset of the printable ASCII set, such as [a-Z][A-Z][0-9].

Thanks

• Welcome to Cryptography. This is not about Cryptography, this is about encoding the output. Look for base64 or Binary to Text encoding. – kelalaka Feb 13 at 9:18
• Having a base that is a power of two is highly recommended of course, otherwise you may have to use big integers for your base conversion (or use escaping for some values). The output of almost all modern crypto functions is binary after all. Your ASCII consists of 62 characters, which is not a good idea in that sense. – Maarten Bodewes Feb 13 at 14:53

To have base 62 (as specified in your question) is much harder, as 62 is not a power of two. That means that you either need to perform base conversion using big integer calculations (divide-and-remainder) or you'll have to convert to base64 and escape out three characters (the +, the /` and the escape character itself). Escaping will result in a variable length encoding though, maxing out on doubling the base64 string in size.