Why not use Base64, but convert the + and / characters to - and _, respectively? See http://en.wikipedia.org/wiki/Base64#Variants_summary_table for a description.
This is pretty commonly used, perhaps most famously by YouTube for their video ids.
This code turns a 64-bit value into a base64 encoded key, using that conversion:
    public static string Base64EncodeKey(ulong key)
    {
        // get bytes
        byte[] keyBytes = BitConverter.GetBytes(key);
        // get base64 value
        string keyString = Convert.ToBase64String(keyBytes);
        // The base64 encoding has a trailing = sign, and + and - characters.
        // Strip the trailing =.
        keyString = keyString.Substring(0, keyString.Length - 1);
        // convert + to - (dash) and / to _ (underscore)
        keyString = keyString.Replace('+', '-');
        keyString = keyString.Replace('/', '_');
        return keyString;
    }
The reverse turns the encoded key back to a ulong:
    public static ulong Base64DecodeKey(string keyString)
    {
        // convert - to +, and _ to /
        keyString = keyString.Replace('-', '+');
        keyString = keyString.Replace('_', '/');
        // add the trailing =
        keyString += '=';
        // convert to bytes
        byte[] keyBytes = Convert.FromBase64String(keyString);
        // get the encoded key
        ulong encodedKey = BitConverter.ToUInt64(keyBytes, 0);
        return encodedKey;
    }
You can do something similar with 32-bit keys.
Update:
I see that you said there's a varying number of bytes. If you know that the value is always 32 bits or less (or 64 bits or less), you're probably better off using the technique I described above. If you really need to encode a varying length string, you can still use the modified base64 encoding scheme that replaces + and / with - and _. See RFC 4648 for other recommendations.