I need efficient way(possibly as strong as AES or AES itself) to enrypt (only) aplhanumeric data and get out only alphanumeric data, using some known library (i don't want and intend to implement AES myself).
closed as off-topic by D3C4FF, TildalWave, Adnan, Scott Pack, Gilles Jul 6 at 20:45
- This question does not appear to be about Information security within the scope defined in the help center.
Encode the input as some bytes, encrypt that, and encode the encryption output in hexadecimal, which is, by definition, alphanumeric. This is simple enough to implement and will piggyback on an existing implementation of AES or whatever encryption system you envision.
Now this will imply some growth in size, because:
Some of these growth elements can be mitigated. For instance, if the encryption mode you use is GCM or EAX, then there will be no need for padding, the extra size for the MAC part will be limited (16 bytes)(and a very nice property of GCM and EAX is that they take care of the MAC in a cryptographically sound way, contrary to most homemade constructions) and the IV needs only be unique, not random, and thus can be a simple counter (which could be encoded over four bytes or so, depending on the context). Also, you could replace hexadecimal with Base64, which implies less growth (note that raw Base64 uses both lowercase and uppercase letters with distinct meanings; also, it uses two extra non-alphanumeric characters '+' and '/'; but a Base62 encoding which uses only digits and letters would not be hard to design and implement).
If the output must have the same size as the input, then things become a lot more tricky. You won't be able to reuse an existing library, or even AES at all. This is the realm of Format Preserving Encryption, which is more a research area than a tool ready for production, unless you are a trained cryptographer and you know what you are doing, in which case everything I wrote above was trivial (for you) and you needn't read it.