private static byte[] encode(final byte[] in, final byte[] map) {
            final int length = 4 * (in.length / 3) + (in.length % 3 == 0 ? 0 : in.length % 3 + 1);
            final byte[] out = new byte[length];
            int index = 0;
            final int end = in.length - in.length % 3;
            for (int i = 0; i < end; i += 3) {
                out[index++] = map[(in[i] & 0xff) >> 2];
                out[index++] = map[((in[i] & 0x03) << 4) | ((in[i + 1] & 0xff) >> 4)];
                out[index++] = map[((in[i + 1] & 0x0f) << 2) | ((in[i + 2] & 0xff) >> 6)];
                out[index++] = map[(in[i + 2] & 0x3f)];
            }
            switch (in.length % 3) {
                case 1:
                    out[index++] = map[(in[end] & 0xff) >> 2];
                    out[index] = map[(in[end] & 0x03) << 4];
                    break;
                case 2:
                    out[index++] = map[(in[end] & 0xff) >> 2];
                    out[index++] = map[((in[end] & 0x03) << 4) | ((in[end + 1] & 0xff) >> 4)];
                    out[index] = map[((in[end + 1] & 0x0f) << 2)];
                    break;
                default:
            }
            return out;
        }
A mod of Square's Okio Base64 encoder
<p>
Original author: Alexander Y. Kleymenov

@see <a href="https://github.com/square/okio/blob/okio-parent-1.15.0/okio/src/main/java/okio/Base64.java">Okio</a>
crypto/support/hashes/bcrypt/src/main/java/org/apache/shiro/crypto/support/hashes/bcrypt/OpenBSDBase64.java