public static byte[] decode(byte[] source){
    //the length of the original array
    int len = source.length;
    //determine the length of the target array
    int len34 = len * 3 / 4;
    //this is the target array and its index
    byte[] targetArray = new byte[len34]; //maximum size
    int targetIndex = 0;
    //auxuiliar array to group 4 bytes to be decoded and its index
    byte[] aux = new byte[4];
    int auxPos = 0;
    //index for the "for" loop
    int    i         = 0;
    //variables to manage the bytes
    byte   sbiCrop   = 0;
    byte   sbiDecode = 0;

    //The "for" loop will go trough all the bytes. Inside it will be
    //creating an array of 4 bytes to be decoded to 3 bytes.
    for(i = 0; i < len; i++){
      //we take only the lowest 7 bits, because they represent the possible
      //characters we expect (from 0 to 127)
      sbiCrop = (byte)(source[i] & 0x7f);
      //get the corresponding value for this ASCII value. For example:
      //'A' (ASCII 65) is represented in the base64 table as the value 0,
      //'B' (ASCII 66) is represented in the base64 table as the value 1, and so on
      sbiDecode = DECODE_TABLE64[sbiCrop];

      //it means that it can be a white space (-5), equals character (-1) or
      //one of the characters from the base64 table (A-Z,a-z,0-9,+,/)
      if( sbiDecode >= WHITE_SPACE_ENC ) {
        if( sbiDecode >= EQUALS_SIGN_ENC ) {
          //store this byte in the auxiliar array
          aux[auxPos++] = sbiCrop;
          //if we have already 4 bytes, then it is time to decode them...
          if(auxPos > 3) {
            //decode the 4 bytes from the array "b4", starting in the position "0",
            //into the "targetArray", starting in the position "targetIndex".
            //targetIndex is incremented by the number of bytes written to targetArray
            //it will be normally incremented by 3
            targetIndex += decode4Bytes(aux, 0, targetArray, targetIndex);
            //reset it to be able to group the next 4 bytes
            auxPos = 0;

            //If the byte was "=", then break out of the "for" loop, because there
            //are no more bytes to be decoded
            if( sbiCrop == EQUALS_CHAR )
              break;
          }//if we have 4 bytes

        }//if it is "=" or other base64 valid character

      }//if it was white space, "=" or other base64 valid character
      else {
        System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" );
        return null;
      }//else

    }//for each byte

    //create a new array with the real size (without considering spaces)
    byte[] out = new byte[targetIndex];
    //copy the target array to the new array (only the first targetIndex elements)
    System.arraycopy(targetArray, 0, out, 0, targetIndex);
    return out;

  }//decode