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.doculibre.constellio.utils.aes.SimpleProtector.java

public static String encrypt(String valueToEnc) throws Exception {
    Key key = generateKey();/*from ww w .j a  v  a 2 s  . c  o  m*/
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encValue = c.doFinal(valueToEnc.getBytes());
    String encryptedValue = Base64.encodeBase64String(encValue);
    return encryptedValue;
}

From source file:net.arccotangent.pacchat.crypto.MsgCrypto.java

public static String encryptAndSignMessage(String msg, PublicKey publicKey, PrivateKey privateKey) {
    mc_log.i("Encrypting and signing message.");
    SecretKey aes = AES.generateAESKey();

    assert aes != null;

    byte[] aesCryptedText = AES.encryptBytes(msg.getBytes(), aes);
    byte[] cryptedAesKey = RSA.encryptBytes(aes.getEncoded(), publicKey);

    byte[] signature = RSA.signBytes(cryptedAesKey, privateKey);

    String cryptedTextB64 = Base64.encodeBase64String(aesCryptedText);
    String cryptedKeyB64 = Base64.encodeBase64String(cryptedAesKey);
    String signatureB64 = Base64.encodeBase64String(signature);

    return cryptedKeyB64 + "\n" + cryptedTextB64 + "\n" + signatureB64;
}

From source file:io.cloudslang.content.database.utils.TripleDES.java

/**
 * encrypt a plain password/*  w w  w . j a  v a  2  s. c om*/
 *
 * @param aPlainPass a password in plain text
 * @return an encrypted password
 * @throws Exception
 */
public static String encryptPassword(@NotNull final String aPlainPass) throws Exception {
    byte[] encBytes = encryptString(aPlainPass.getBytes(DEFAULT_CODEPAGE));
    return Base64.encodeBase64String(encBytes);
}

From source file:love.sola.netsupport.util.RSAUtil.java

public static void genKeyPair() {
    try {//from   w w  w  .  j  ava  2s. c  o m
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        kpg.initialize(1024);
        KeyPair kp = kpg.genKeyPair();
        publicKey = kp.getPublic();
        privateKey = kp.getPrivate();
        publicKey_s = Base64.encodeBase64String(publicKey.getEncoded());
        privateKey_s = Base64.encodeBase64String(privateKey.getEncoded());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:in.bookmylab.Utils.java

public static String hashPassword(String password) {
    String hashed = null;/*from  ww w. j  av a 2 s . c  om*/
    try {
        if (!StringUtils.isBlank(password)) {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest((salt + password).getBytes(StandardCharsets.ISO_8859_1));
            //hashed = Base64.getEncoder().encodeToString(hash);
            hashed = Base64.encodeBase64String(hash);
        }
    } catch (NoSuchAlgorithmException ex) {
        log.log(Level.SEVERE, "Could not hash string.", ex);
    }
    return hashed;
}

From source file:$.Encodes.java

/**
     * Base64?./* ww  w  .j ava  2  s .com*/
     */
    public static String encodeBase64(byte[] input) {
        return Base64.encodeBase64String(input);
    }

From source file:com.streamsets.pipeline.lib.el.Base64EL.java

@ElFunction(prefix = "base64", name = "encodeBytes", description = "Returns base64 encoded version of the string argument.")
public static String base64Encode(@ElParam("string") byte[] bytes, @ElParam("urlSafe") boolean urlSafe) {
    if (urlSafe) {
        return Base64.encodeBase64URLSafeString(bytes);
    } else {//from  w  w  w.  j a  v  a2 s .c  o m
        return Base64.encodeBase64String(bytes);
    }
}

From source file:com.govsoft.framework.common.util.encode.EncodeUtils.java

/**
 * Base64?, byte[]->String.//from w  ww .  jav a 2s .c o  m
 */
public static String base64Encode(byte[] input) {
    return Base64.encodeBase64String(input);
}

From source file:com.lwr.software.reporter.utils.EncryptionUtil.java

public static String encrypt(String value) {
    try {/*w  w  w. ja  v  a  2s. c  om*/
        IvParameterSpec iv = new IvParameterSpec(
                DashboardConstants.INIT_VECTOR.getBytes(DashboardConstants.ENCODING));
        SecretKeySpec skeySpec = new SecretKeySpec(
                DashboardConstants.INIT_KEY.getBytes(DashboardConstants.ENCODING),
                DashboardConstants.ALGORITHM);
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] encrypted = cipher.doFinal(value.getBytes());
        return Base64.encodeBase64String(encrypted);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.wx.serveplatform.common.utils.Encodes.java

/**
 * Base64?.//  www  . j av  a 2s  .com
 */
public static String encodeBase64(String input) {
    try {
        return Base64.encodeBase64String(input.getBytes(DEFAULT_URL_ENCODING));
    } catch (UnsupportedEncodingException e) {
        return "";
    }
}