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

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

Introduction

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

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm but does not chunk the output.

Usage

From source file:com.zotoh.maedr.device.netty.NettpHplr.java

/**
 * @param key/*from   w ww . j  av a2  s .  co  m*/
 * @return
 */
public static String calcHybiSecKeyAccept(String key) {
    // add fix GUID according to 
    // http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10
    String k = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
    String rc = "";
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] bits = md.digest(k.getBytes("utf-8"));
        rc = Base64.encodeBase64String(bits);
    } catch (Exception e) {
        //TODO
    }
    return rc;
}

From source file:com.liferay.sync.engine.util.FileUtil.java

public static String getChecksum(Path filePath) throws IOException {
    if (!Files.exists(filePath) || (Files.size(filePath) > PropsValues.SYNC_FILE_CHECKSUM_THRESHOLD_SIZE)) {

        return "";
    }/*from   w w w. jav a  2 s . co  m*/

    InputStream fileInputStream = null;

    try {
        fileInputStream = Files.newInputStream(filePath);

        byte[] bytes = DigestUtils.sha1(fileInputStream);

        return Base64.encodeBase64String(bytes);
    } finally {
        StreamUtil.cleanUp(fileInputStream);
    }
}

From source file:cr.ac.uia.SistemaGC.utils.AES.java

public static String encrypt(Long cedula, String usuario, String contrasena) {
    //<editor-fold defaultstate="collapsed" desc="Mtodo para cifrar contraseas">
    /*//from w  w  w.  jav  a2s  .  c  o  m
    * Inspirado en:
    * http://stackoverflow.com/questions/15554296/simple-java-aes-encrypt-decrypt-example
     */
    try {
        IvParameterSpec iv = new IvParameterSpec(fitString(usuario, 16).getBytes("UTF-8"));
        SecretKeySpec skeySpec = new SecretKeySpec(fitString(cedula.toString(), 16).getBytes("UTF-8"), "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] encrypted = cipher.doFinal(contrasena.getBytes());
        return Base64.encodeBase64String(encrypted);
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException
            | BadPaddingException e) {
        e.printStackTrace();
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
    }
    return null;
    //</editor-fold>
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java

public String sha1(String data) {
    return Base64.encodeBase64String(DigestUtils.sha1(data));
}

From source file:encrypt.algorithms.AESCBC.java

public String encrypt(String key1, String key2, String value) {
    try {//w  w  w . j  av a  2s .c  o m
        IvParameterSpec iv = new IvParameterSpec(key2.getBytes("UTF-8"));

        SecretKeySpec skeySpec = new SecretKeySpec(key1.getBytes("UTF-8"), "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] encrypted = cipher.doFinal(value.getBytes());
        // System.out.println("encrypted string:"
        //       + Base64.encodeBase64String(encrypted));
        return Base64.encodeBase64String(encrypted);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.mnr.java.intellij.idea.plugin.base64helper.EncoderPopupItem.java

@Override
public String encodeDecode(String selectedText) {
    return Base64.encodeBase64String(selectedText.getBytes());
}

From source file:com.cprassoc.solr.auth.security.Sha256AuthenticationProvider.java

static void putUser(String user, String pwd, Map credentials) {
    if (user == null || pwd == null)
        return;/* ww w.j a v  a  2  s  . co m*/

    final Random r = new SecureRandom();
    byte[] salt = new byte[32];
    r.nextBytes(salt);
    String saltBase64 = Base64.encodeBase64String(salt);
    String val = sha256(pwd, saltBase64) + " " + saltBase64;
    credentials.put(user, val);
}

From source file:net.bryansaunders.jee6divelog.util.HashUtils.java

/**
 * Encodes a string as Base64./*w  w w. j ava2s .c o m*/
 * 
 * @param stringToEncode
 *            String to encode
 * @return Encoded String
 */
public static String base64Encode(final String stringToEncode) {
    return Base64.encodeBase64String(stringToEncode.getBytes());
}

From source file:net.algem.security.CustomPasswordEncoder.java

@Override
public String encodePassword(String rawPass, Object salt) throws DataAccessException {
    byte[] crypted = null;
    try {//from www .  j  a  va 2s.com
        byte[] b64salt = Base64.decodeBase64((String) salt);
        crypted = service.getEncryptedPassword(rawPass, b64salt);
    } catch (UserException ex) {
        return "";
    }
    return Base64.encodeBase64String(crypted);
}

From source file:com.trimble.tekla.teamcity.HttpConnector.java

public void Post(TeamcityConfiguration conf, String url, Map<String, String> parameters) {

    try {//from   w  ww.j  a v  a 2s. c  o m

        String urlstr = conf.getUrl() + url;

        URL urldata = new URL(urlstr);
        logger.warn("Hook Request: " + urlstr);

        String authStr = conf.getUserName() + ":" + conf.getPassWord();
        String authEncoded = Base64.encodeBase64String(authStr.getBytes());

        HttpURLConnection connection = (HttpURLConnection) urldata.openConnection();

        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Authorization", "Basic " + authEncoded);

        InputStream content = (InputStream) connection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(content));

        StringBuilder dataout = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            dataout.append(line);
        }

        logger.warn("Hook Reply: " + line);

    } catch (Exception e) {
        logger.debug("Hook Exception: " + e.getMessage());
        e.printStackTrace();
    }
}