private static byte [ ] decodeBytes ( byte [ ] pInBytes ) { byte [ ] decodabet = DECODABET ; int len34 = pInBytes . length * 3 / 4 ; // Estimate on array size byte [ ] outBuff = new byte [ len34 ] ; // Upper limit on size of output int outBuffPosn = 0 ; // Keep track of where we're writing byte [ ] b4 = new byte [ 4 ] ; // Four byte buffer from source, eliminating white space int b4Posn = 0 ; // Keep track of four byte input buffer int i = 0 ; // Source array counter byte sbiCrop = 0 ; // Low seven bits (ASCII) of input byte sbiDecode = 0 ; // Special value from DECODABET for ( i = 0 ; i < 0 + pInBytes . length ; i ++ ) { // Loop through source sbiCrop = ( byte ) ( pInBytes [ i ] & 0x7f ) ; // Only the low seven bits sbiDecode = decodabet [ sbiCrop ] ; // Special value // White space, Equals sign, or legit Base64 character // Note the values such as -5 and -9 in the // DECODABETs at the top of the file. if ( sbiDecode >= WHITE_SPACE_ENC ) { if ( sbiDecode >= EQUALS_SIGN_ENC ) { b4 [ b4Posn ++ ] = sbiCrop ; // Save non-whitespace if ( b4Posn > 3 ) { // Time to decode? outBuffPosn += decode4to3 ( b4 , 0 , outBuff , outBuffPosn ) ; b4Posn = 0 ; // If that was the equals sign, break out of 'for' loop if ( sbiCrop == EQUALS_SIGN ) { break ; } } } } else { // There's a bad input character in the Base64 stream. throw new IllegalArgumentException ( String . format ( "Bad Base64 input character '%d' in array position %d" , pInBytes [ i ] , i ) ) ; } } byte [ ] out = new byte [ outBuffPosn ] ; System . arraycopy ( outBuff , 0 , out , 0 , outBuffPosn ) ; return out ; }
Do the conversion to bytes