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:cn.newtouch.util.utils.encode.EncodeUtils.java

/**
 * Base64?.
 */
public static byte[] base64Decode(String input) {
    return Base64.decodeBase64(input);
}

From source file:com.google.u2f.TestUtils.java

public static byte[] parseBase64(String base64Encoded) {
    return Base64.decodeBase64(base64Encoded);
}

From source file:com.yahoo.yos.RequestToken.java

public RequestToken(Cookie cookie) throws UnsupportedEncodingException, JSONException {
    JSONObject json = new JSONObject(
            new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8"));
    setKey(json.optString("key", null));
    setSecret(json.optString("secret", null));
    setSessionHandle(json.optString("sessionHandle", null));
}

From source file:Componentes.EncryptionMD5.java

public static String Desencriptar(String encriptado) {
    System.out.println(encriptado);
    String secretKey = "qualityinfosolutions"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {//  ww  w. j a  va2s.  c o  m
        System.out.println("h");
        byte[] message = Base64.decodeBase64(encriptado.getBytes("utf-8"));
        System.out.println("b");
        MessageDigest md = MessageDigest.getInstance("MD5");
        System.out.println("a");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        System.out.println("c");
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        System.out.println("g");
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        System.out.println("w");
        Cipher decipher = Cipher.getInstance("DESede");
        System.out.println("t");
        decipher.init(Cipher.DECRYPT_MODE, key);
        System.out.println("r");
        System.out.println(Arrays.toString(message));
        byte[] plainText = decipher.doFinal(message);
        System.out.println(Arrays.toString(plainText));
        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return base64EncryptedString;
}

From source file:jshm.util.Crypto.java

public static String decrypt(String cipherText) {
    LOG.finest("entered Crypto.decrypt()");

    LOG.finer("Base64 decoding cipherText");

    try {/*from ww w. j ava2 s .c o m*/
        cipherText = new String(Base64.decodeBase64(cipherText.getBytes()));
    } catch (ArrayIndexOutOfBoundsException e) {
        // this is only necessary to deal with passwords that were
        // previously encoded via the old javax.crypto.* method

        LOG.info("Clearing password to handle new storage mechanism");
        LOG.log(Level.FINER, "Exception from old password", e);
        cipherText = "";
    }

    LOG.finest("exiting Crypto.decrypt()");
    return cipherText;
}

From source file:com.philosophy.LicenseDecoder.java

public LicenseDecoder(String text) {
    license = text;/* w  w w  .  j  av a2 s.  c o m*/
    byte[] keyBytes = { 88, 42, 94, 52, 56, 81, 82, 98 };
    System.out.println("Original License : " + license);
    try {
        SecretKey key = new SecretKeySpec(keyBytes, "DES");
        Cipher cipher = Cipher.getInstance("DES");
        byte[] decoded = Base64.decodeBase64(license.getBytes());
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decrypted = cipher.doFinal(decoded);
        System.out.println("Decrypted license : " + new String(decrypted));
    } catch (NoSuchAlgorithmException e) {
    } catch (NoSuchPaddingException e) {
    } catch (InvalidKeyException e) {
    } catch (IllegalStateException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (BadPaddingException e) {
    }
}

From source file:com.aqnote.shared.cryptology.cert.util.KeyStoreFileUtil.java

public static void writePkcsFile(String b64P12, String p12fileName) throws IOException {

    if (StringUtils.isBlank(p12fileName) || StringUtils.isBlank(b64P12)) {
        return;//from   w w  w .j  a va2s .  c om
    }
    byte[] p12File = Base64.decodeBase64(b64P12);
    FileOutputStream fos = new FileOutputStream(p12fileName);
    fos.write(p12File);
    fos.flush();
    fos.close();
}

From source file:de.uzk.hki.da.utils.PasswordUtils.java

public static String decryptPassword(String password) {

    byte key[] = "394z57f4".getBytes();
    byte decryptedPassword[];

    try {//from www .  j  av  a  2s .c o m
        SecretKey secretKey = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(key));
        Cipher decrypt = Cipher.getInstance("DES/CBC/PKCS5Padding");
        decrypt.init(Cipher.DECRYPT_MODE, secretKey,
                new IvParameterSpec(new byte[] { 0x01, 0x02, 0x04, 0x10, 0x01, 0x02, 0x04, 0x10 }));
        decryptedPassword = decrypt.doFinal(Base64.decodeBase64(password.getBytes()));

    } catch (GeneralSecurityException e) {
        throw new RuntimeException("Couldn't decrypt password " + password + e);
    }

    return new String(decryptedPassword);
}

From source file:com.apabi.qrcode.utils.EncodeUtils.java

/**
 * Base64?.//from  w  ww. jav  a2  s  . c  o  m
 */
public static byte[] base64Decode(final String input) {
    return Base64.decodeBase64(input);
}

From source file:com.doculibre.constellio.utils.aes.SimpleProtector.java

public static String decrypt(String encryptedValue) throws Exception {
    Key key = generateKey();// ww  w  .  ja  v  a  2s .  c  o  m
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.DECRYPT_MODE, key);
    byte[] decordedValue = Base64.decodeBase64(encryptedValue);
    byte[] decValue = c.doFinal(decordedValue);
    String decryptedValue = new String(decValue);
    return decryptedValue;
}