Java XML Data Type Converter decode(String auth)

Here you can find the source of decode(String auth)

Description

decode

License

Open Source License

Declaration

public static String[] decode(String auth) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;

public class Main {
    public static String[] decode(String auth) {
        // Replacing "Basic THE_BASE_64" to "THE_BASE_64" directly
        auth = auth.replaceFirst("[B|b]asic ", "");

        // Decode the Base64 into byte[]
        byte[] decodedBytes = DatatypeConverter.parseBase64Binary(auth);

        // If the decode fails in any case
        if (decodedBytes == null || decodedBytes.length == 0) {
            return null;
        }//w w w.j a  v a 2s.co m

        // Now we can convert the byte[] into a splitted array :
        // - the first one is login,
        // - the second one password
        return new String(decodedBytes).split(":", 2);
    }
}

Related

  1. convertToFourBytes(int numberToConvert)
  2. convertToPEM(PublicKey key)
  3. convertToTwoBytes(int numberToConvert)
  4. createBasicAuthenticationProperty(final String username, final String password)
  5. decode(final CharSequence _text)
  6. decode(String source)
  7. decode(String string, boolean decode)
  8. decodeBasicAuth(String auth)
  9. decodeJavaOpts(String encodedJavaOpts)