Example usage for org.apache.commons.codec.binary Base64 decodeBase64

List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 decodeBase64.

Prototype

public static byte[] decodeBase64(final byte[] base64Data) 

Source Link

Document

Decodes Base64 data into octets

Usage

From source file:fr.ippon.wip.ltpa.token.LtpaLibrary.java

/**
 * This method parses the LtpaToken cookie received from the web browser and returns the information in the <tt>TokenData</tt>
 * class.//from w  w w . j a  v  a 2  s  .c o  m
 *
 * @param ltpaToken     - the cookie (base64 encoded).
 * @param ltpaSecretStr - the contents of the <tt>LTPA_DominoSecret</tt> field from the SSO configuration document.
 * @return The contents of the cookie. If the cookie is invalid (the hash - or some other - test fails), this method returns
 *         <tt>null</tt>.
 * @throws NoSuchAlgorithmException
 */
public static TokenData parseLtpaToken(String ltpaToken, String ltpaSecretStr) throws NoSuchAlgorithmException {
    byte[] data = Base64.decodeBase64(ltpaToken.getBytes());

    int variableLength = data.length - hashLength;
    /* Compare to 20 to since variableLength must be at least (preUserDataLength + 1) [21] character long:
       * Token version: 4 bytes
       * Token creation: 8 bytes
       * Token expiration: 8 bytes
       * User name: variable length > 0
       */
    if (variableLength <= preUserDataLength)
        return null;

    byte[] ltpaSecret = Base64.decodeBase64(ltpaSecretStr.getBytes());

    if (!validateSHA(data, variableLength, ltpaSecret))
        return null;

    if (!compareBytes(data, 0, ltpaTokenVersion, 0, ltpaTokenVersion.length))
        return null;

    TokenData ret = new TokenData();
    ret.tokenCreated.setTimeInMillis(
            (long) Integer.parseInt(getString(data, creationDatePosition, dateStringLength), 16) * 1000);
    ret.tokenExpiration.setTimeInMillis(
            (long) Integer.parseInt(getString(data, expirationDatePosition, dateStringLength), 16) * 1000);

    byte[] nameBuffer = new byte[data.length - (preUserDataLength + hashLength)];
    System.arraycopy(data, preUserDataLength, nameBuffer, 0, variableLength - preUserDataLength);
    ret.username = new String(nameBuffer);

    return ret;
}

From source file:com.vss.ogc.types.WkbGzSerializer.java

@Override
public Geometry toGeometry(String value) throws InvalidGeometryException {
    return value.isEmpty() ? GeoConvert.getEmptyGeometry()
            : AbstractGeo.binaryToGeometry(AbstractGeo.gunzip(Base64.decodeBase64(value.getBytes())));
}

From source file:com.dv.sharer.restclients.ImageRestClient.java

public byte[] downloadFile(String id) throws ClientErrorException {
    WebTarget resource = getWebTarget();
    resource = resource.path(MessageFormat.format("download/{0}", new Object[] { id }));
    String response = resource.request(MediaType.TEXT_PLAIN).get(String.class);
    return Base64.decodeBase64(response);
}

From source file:com.fortmoon.utils.SymmetricCypher.java

public SymmetricCypher() {
    cipherTransformation = "AES";
    keyAlgorithm = "AES";
    secretKeySpec = new SecretKeySpec(Base64.decodeBase64(salt.getBytes()), keyAlgorithm);
}

From source file:net.duckling.ddl.util.EncodeUtil.java

public static String[] getDecodeArray(String downloadURL) {
    byte[] byteArray = Base64.decodeBase64(downloadURL.getBytes());
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < byteArray.length; i++) {
        sb.append((char) byteArray[i]);
    }//www . j  av  a2  s  .c  o  m
    String decodeURL = sb.toString();
    String[] tempArray = decodeURL.split("#");
    return tempArray;
}

From source file:br.com.topsys.cd.applet.AssinaturaApplet.java

@Override
public void complemento(CertificadoDigital certificadoDigital) {

    this.certificadoDigital = certificadoDigital;
    JSObject window = JSObject.getWindow(this);

    window.call("setHash", new Object[] { this.assinar(this.dados) });

    if (super.relatorio != null && !super.relatorio.equals("")) {
        window.call("setRelatorio", new Object[] { this.assinar(Base64.decodeBase64(super.relatorio)) });
    }/*  ww w. ja v  a 2s.  c o m*/

    this.closeSuccess();

}

From source file:com.vss.ogc.types.WktGzSerializer.java

@Override
public Geometry toGeometry(String value) throws InvalidGeometryException {
    return value.isEmpty() ? GeoConvert.getEmptyGeometry()
            : GeoConvert.wktToGeometry(new String(AbstractGeo.gunzip(Base64.decodeBase64(value.getBytes()))));
}

From source file:com.vvote.verifierlibrary.utils.Utils.java

/**
 * Decodes a string in base64 format into byte format
 * /*from ww  w  .j a  va 2s.co  m*/
 * @param data
 * @return byte data
 */
public static byte[] decodeBase64Data(String data) {
    return Base64.decodeBase64(data);
}

From source file:com.paypal.utilities.AESDecrypt.java

public AESDecrypt(String encryptedString) throws Exception {
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec keySpec = new PBEKeySpec(passphrase.toCharArray(), SALT, ITERATION_COUNT, KEY_LENGTH);
    SecretKey secretKeyTemp = secretKeyFactory.generateSecret(keySpec);
    SecretKey secretKey = new SecretKeySpec(secretKeyTemp.getEncoded(), "AES");

    encrypt = Base64.decodeBase64(encryptedString.getBytes());

    eCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    eCipher.init(Cipher.ENCRYPT_MODE, secretKey);

    byte[] iv = extractIV();
    dCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    dCipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
}

From source file:common.Util.java

public static boolean writeFile64(File file, byte[] base64Data) {
    return writeFile(file, Base64.decodeBase64(base64Data));
}