Java XML Data Type Converter decodeBasicAuth(String auth)

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

Description

decode Basic Auth

License

Open Source License

Parameter

Parameter Description
auth a parameter

Declaration

public static String[] decodeBasicAuth(String auth) 

Method Source Code

//package com.java2s;
/*//  w  w w .  ja  va  2s.  co m
 * Copyright (C) 2015 Telecom Italia S.p.A.
 *
 * This file is part of Metaware.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Marco Terrinoni marco.terrinoni at consoft.it
 */

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     *
     * @param auth
     * @return
     */
    public static String[] decodeBasicAuth(String auth) {
        String uap = auth.replaceFirst("[B|b]asic", ""); // remove "(B|b)asic" from the string
        byte[] decodedBytes = DatatypeConverter.parseBase64Binary(uap);
        if (decodedBytes == null || decodedBytes.length == 0) {
            return null;
        } else {
            return new String(decodedBytes).split(":", 2);
        }
    }
}

Related

  1. createBasicAuthenticationProperty(final String username, final String password)
  2. decode(final CharSequence _text)
  3. decode(String auth)
  4. decode(String source)
  5. decode(String string, boolean decode)
  6. decodeJavaOpts(String encodedJavaOpts)
  7. decodeToDoubleArray(String encoded)
  8. decrypt(String encryptedText, String password)
  9. deCrypt(String property)