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:io.kahu.hawaii.util.encryption.CryptoUtil.java

public static String decrypt(String encrypted, String key, String initVector) throws ServerException {
    try {//from ww  w .j  ava  2  s.c  om
        Cipher cipher = initCipher(Cipher.DECRYPT_MODE, key, initVector);

        byte[] decrypted = cipher.doFinal(Base64.decodeBase64(encrypted));

        return new String(decrypted);
    } catch (GeneralSecurityException e) {
        throw new ServerException(ServerError.ENCRYPTION, e);
    }
}

From source file:com.esri.geoevent.datastore.Crypto.java

static public String doDecrypt(String stringToDecrypt) throws GeneralSecurityException {
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.DECRYPT_MODE, encryptionKey);
    byte[] decodedValue = Base64.decodeBase64(stringToDecrypt.getBytes());
    byte[] decryptedValue = c.doFinal(decodedValue);
    String decryptedString = new String(decryptedValue);
    return decryptedString;
}

From source file:$.Encodes.java

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

From source file:com.continusec.client.LogTreeHead.java

/**
 * Create object from a Gson JsonObject.
 * @param o the Gson object.//from   w w w .  j av a2  s  .  co  m
 * @return the log tree hash.
 */
protected static LogTreeHead fromJsonObject(JsonObject o) {
    JsonElement e2 = o.get("tree_hash");
    if (e2.isJsonNull()) {
        return new LogTreeHead(o.get("tree_size").getAsInt(), null);
    } else {
        return new LogTreeHead(o.get("tree_size").getAsInt(), Base64.decodeBase64(e2.getAsString()));
    }
}

From source file:com.barrybecker4.common.util.Base64Codec.java

/**
 * Take a String and decompress it.//w ww.  j a v  a  2  s  . co  m
 * @param data the compressed string to decompress.
 * @return the decompressed string.
 */
public static synchronized String decompress(final String data) {

    // convert from string to bytes for decompressing
    byte[] compressedDat = Base64.decodeBase64(data.getBytes());

    final ByteArrayInputStream in = new ByteArrayInputStream(compressedDat);
    final Inflater inflater = new Inflater();
    final InflaterInputStream iStream = new InflaterInputStream(in, inflater);
    final char cBuffer[] = new char[4096];
    StringBuilder sBuf = new StringBuilder();
    try {
        InputStreamReader iReader = new InputStreamReader(iStream, CONVERTER_UTF8);
        while (true) {
            final int numRead = iReader.read(cBuffer);
            if (numRead == -1) {
                break;
            }
            sBuf.append(cBuffer, 0, numRead);
        }
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e);
    } catch (IOException e) {
        throw new IllegalStateException("io error :" + e.getMessage(), e);
    }

    return sBuf.toString();
}

From source file:com.searchbox.utils.DecryptLicense.java

public static byte[] decrypt(byte[] inpBytes) throws Exception {

    byte[] pkbytes = Base64.decodeBase64(privkey);
    KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
    PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(pkbytes);
    PrivateKey pk = keyFactory.generatePrivate(privateKeySpec);

    Cipher cipher = Cipher.getInstance(xform);
    cipher.init(Cipher.DECRYPT_MODE, pk);
    return cipher.doFinal(inpBytes);
}

From source file:com.cnd.greencube.web.base.filter.AccessDeniedFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"),
            new String(Base64.decodeBase64("VG9wIFRlYW0="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}

From source file:com.ec2box.manage.util.EncryptionUtil.java

/**
 * return hash value of string/*w  ww . j  a  va2  s  .  co m*/
 *
 * @param str  unhashed string
 * @param salt salt for hash
 * @return hash value of string
 */
public static String hash(String str, String salt) {
    String hash = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        if (StringUtils.isNotEmpty(salt)) {
            md.update(Base64.decodeBase64(salt.getBytes()));
        }
        md.update(str.getBytes("UTF-8"));
        hash = new String(Base64.encodeBase64(md.digest()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hash;
}

From source file:com.keybox.manage.util.EncryptionUtil.java

/**
 * return hash value of string/*from   ww w . jav  a2s  . co  m*/
 *
 * @param str  unhashed string
 * @param salt salt for hash
 * @return hash value of string
 */
public static String hash(String str, String salt) {
    String hash = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        if (StringUtils.isNotEmpty(salt)) {
            md.update(Base64.decodeBase64(salt.getBytes()));
        }
        md.update(str.getBytes("UTF-8"));
        hash = new String(Base64.encodeBase64(md.digest()));
    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    return hash;
}

From source file:com.clearspring.analytics.stream.membership.Base64Test.java

@Test
public void testBase64EncodedBloomFilter() throws IOException, ClassNotFoundException {
    BloomFilter bf = BloomFilter.deserialize(Base64.decodeBase64(Resources.toString(
            Resources.getResource(Base64Test.class, "encoded_random_keys.bloom"), Charset.forName("UTF-8"))));
    assertTrue(bf.isPresent("4a7137513e61adbb"));
    assertTrue(bf.isPresent("4ba145c986af5848"));
    assertTrue(bf.isPresent("4b8c73a241c9d017"));
    assertTrue(bf.isPresent("4bafd549baae6a0c"));
    assertTrue(bf.isPresent("4b98ed851c5fc689"));
    assertTrue(bf.isPresent("4bbead53d3600f7c"));
    assertTrue(bf.isPresent("4bc21f2d4a4a8941"));
    assertTrue(bf.isPresent("4b991b45226abc99"));
    assertFalse(bf.isPresent("blurg"));
    assertFalse(bf.isPresent("bowzer"));
    assertFalse(bf.isPresent("4b991b45226abc90"));
}