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:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java

public String sha256Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha256(Base64.decodeBase64(dataB64)));
}

From source file:com.googlecode.osde.internal.utils.MapUtil.java

public static Map<String, String> toMap(String data) throws IOException, ClassNotFoundException {

    if (StringUtils.isNotBlank(data)) {
        byte[] bytes = data.getBytes("UTF-8");
        byte[] decoded = Base64.decodeBase64(bytes);
        ByteArrayInputStream bais = new ByteArrayInputStream(decoded);
        ObjectInputStream in = new ObjectInputStream(bais);

        @SuppressWarnings("unchecked")
        Map<String, String> result = (Map<String, String>) in.readObject();
        return result;
    }//from  www  .ja  v a  2s . c  o m

    return new HashMap<String, String>();
}

From source file:cd.go.contrib.elasticagents.docker.executors.GetPluginSettingsIconExecutorTest.java

@Test
public void rendersIconInBase64() throws Exception {
    GoPluginApiResponse response = new GetPluginSettingsIconExecutor().execute();
    HashMap<String, String> hashMap = new Gson().fromJson(response.responseBody(), HashMap.class);
    assertThat(hashMap.size(), is(2));/*  w  w w  .j av  a 2s .com*/
    assertThat(hashMap.get("content_type"), is("image/svg+xml"));
    assertThat(Util.readResourceBytes("/docker-plain.svg"), is(Base64.decodeBase64(hashMap.get("data"))));
}

From source file:com.janrain.backplane.common.HmacHashUtils.java

/**
 * @return true if the provided hmacHash matches the password, false otherwise
 *///from   w w w  .ja v  a  2  s  . c o m
public static boolean checkHmacHash(String password, String hmacHash) {
    if (password == null || hmacHash == null)
        return false;

    String[] keyAndSigned = hmacHash.split("\\.");
    if (keyAndSigned.length != 2)
        return false;

    try {
        byte[] encodedKey = Base64.decodeBase64(keyAndSigned[0].getBytes(UTF8_STRING_ENCODING));
        String newSigned = hmacSign(new SecretKeySpec(encodedKey, HMAC_SHA256_ALGORITHM), password);
        String pwdHash = keyAndSigned[1];

        // equal-time compare
        if (newSigned.length() == 0 || newSigned.length() != pwdHash.length())
            return false;
        int result = 0;
        for (int i = 0; i < newSigned.length(); i++) {
            result |= newSigned.charAt(i) ^ pwdHash.charAt(i);
        }
        return result == 0;
    } catch (Exception e) {
        logger.error("Error checking HMAC hash: " + e.getMessage());
        return false;
    }
}

From source file:com.wso2telco.proxy.util.DecryptAES.java

public static String decrypt(String encryptedText) throws NoSuchPaddingException, NoSuchAlgorithmException,
        InvalidKeyException, BadPaddingException, IllegalBlockSizeException, ConfigurationException {
    if (encryptionKey != null) {
        byte[] encryptionKeyByteValue = encryptionKey.getBytes();
        SecretKey secretKey = new SecretKeySpec(encryptionKeyByteValue, AuthProxyConstants.ASE_KEY);
        String decryptedText = null;
        if (encryptedText != null) {
            byte[] encryptedTextByte = Base64.decodeBase64(encryptedText);
            Cipher cipher = Cipher.getInstance("AES");

            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            byte[] decryptedByte = cipher.doFinal(encryptedTextByte);
            decryptedText = new String(decryptedByte);
        }/*from  w  w w .  jav  a2 s.  c  o m*/
        return decryptedText;
    } else {
        throw new ConfigurationException("MSISDN EncryptionKey could not be found in mobile-connect.xml");
    }
}

From source file:com.anjibei.app.framework.listeners.ApplicationListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("Hello. Application Started.");
    System.out.println("Working Dir: " + Application.getWorkingDir().getAbsolutePath());

    String s = new String("tangfuqiang");
    System.out.println("" + s);
    String md5 = MD5Utils.md5(s);

    System.out.println(md5);/*from w  w w. j  a  v a 2s  .  c  om*/

    SecretKey key = AESUtils.generateSecretKey();
    byte[] keyBytes = AESUtils.getKeyBytes(key);
    key = AESUtils.getSecretKey(keyBytes);
    String encrypted = null;
    try {
        encrypted = Base64.encodeBase64String(AESUtils.encrypt(md5, key));
        byte[] decrypted = AESUtils.decrypt(Base64.decodeBase64(encrypted.getBytes("utf-8")), key);
        System.out.println(encrypted);
        System.out.println(new String(decrypted));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

}

From source file:Logi.GSeries.Libraries.Encryption.java

public static String decrypt(String encryptedString, String password) {
    try {/*from ww  w. j  ava2  s.  c o m*/
        byte[] encryptedWithIV = Base64.decodeBase64(encryptedString);
        byte initialVector[] = new byte[16];
        byte[] encrypted = new byte[encryptedWithIV.length - initialVector.length];
        System.arraycopy(encryptedWithIV, 0, encrypted, 0, encrypted.length);
        System.arraycopy(encryptedWithIV, encrypted.length, initialVector, 0, initialVector.length);
        IvParameterSpec ivspec = new IvParameterSpec(initialVector);
        SecretKeySpec skeySpec = new SecretKeySpec(password.getBytes("UTF-8"), "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec);
        byte[] original = cipher.doFinal(encrypted);
        return new String(original);
    } catch (Exception ex) {
        Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        return "Error";
    }
}

From source file:cn.lynx.emi.license.GenerateLicense.java

private static final String encrypt(String key, String data) {
    byte[] corekey = Base64.decodeBase64(key);

    PKCS8EncodedKeySpec pkspec = new PKCS8EncodedKeySpec(corekey);

    try {/*w w  w.  j a v  a2s .  co  m*/
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        Key privateKey = keyFactory.generatePrivate(pkspec);

        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
        cipher.init(Cipher.ENCRYPT_MODE, privateKey);
        byte[] encData = cipher.doFinal(data.getBytes("UTF-8"));
        System.out.println("after encrypt, len=" + encData.length);
        return Base64.encodeBase64String(encData);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.jaspersoft.jasperserver.ps.OAuth.JSONUtils.java

public static JSONObject getClaimsInformationFromAccessTokenAsJsonNode(String tokenString) {
    String[] pieces = splitTokenString(tokenString);
    String jwtHeaderSegment = pieces[0];
    String jwtPayloadSegment = pieces[1];
    byte[] signature = Base64.decodeBase64(pieces[2]);
    ObjectMapper mapper = new ObjectMapper();

    JSONObject myobj;/*  w ww  . ja  va2 s  . co  m*/
    try {
        myobj = new JSONObject(new String(Base64.decodeBase64(jwtPayloadSegment)));
        return myobj;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;

}

From source file:com.lingxiang2014.util.RSAUtils.java

public static String decrypt(PrivateKey privateKey, String text) {
    Assert.notNull(privateKey);//from   w  w  w . j  a v a 2  s.c  om
    Assert.notNull(text);
    byte[] data = decrypt(privateKey, Base64.decodeBase64(text));
    return data != null ? new String(data) : null;
}