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.vvote.verifierlibrary.utils.Utils.java

/**
 * Converts a byte array into base64 string format
 * /*  w ww . ja va 2 s. co m*/
 * @param bytes
 * @return base64 string
 */
public static String byteToBase64String(byte[] bytes) {
    return Base64.encodeBase64String(bytes);
}

From source file:aes_encryption.AES_Encryption.java

public static String encrypt(String strToEncrypt) {
    try {//from   w  w  w.  j a  v  a  2s .co m
        Cipher cipher = Cipher.getInstance("AES_Encryption/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        setEncryptedString(Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes("UTF-8"))));
    } catch (Exception e) {
        System.out.println("Error while encrypting: " + e.toString());
    }
    return null;
}

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

public static String encrypt(String value) {
    try {// w w  w .ja v a  2s. c o m
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8));
        return Base64.encodeBase64String(encrypted);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:inventory.pl.helpers.Encryptor.java

public synchronized String encrypt(String plaintext, boolean useXor) {
    if (useXor)//from w w w .ja  v a  2 s . c  om
        plaintext = getXoredString(plaintext);
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-256"); //step 2
    } catch (NoSuchAlgorithmException e) {

    }
    try {
        md.update(plaintext.getBytes("UTF-8")); //step 3
    } catch (UnsupportedEncodingException e) {

    }

    byte raw[] = md.digest(); //step 4
    String hash = Base64.encodeBase64String(raw); //step 5
    return hash; //step 6
}

From source file:com.apitrary.orm.codec.base64.Base64Codec.java

/** {@inheritDoc} */
@Override
public String encode(byte[] object) {
    return Base64.encodeBase64String(object);
}

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

public String sha1Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha1(Base64.decodeBase64(dataB64)));
}

From source file:com.aast.encrypt.EncryptManager.java

public static String encryptAES(String key, String value) {
    try {//from  w  w w .ja  va  2s. co m
        byte[] keyBytes = getKeyFromString(key);
        IvParameterSpec iv = new IvParameterSpec(keyBytes);
        SecretKeySpec skeySpec = new SecretKeySpec(keyBytes, "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:fr.mael.microrss.util.SecurityUtil.java

public String random() throws NoSuchAlgorithmException {
    SecureRandom random = SecureRandom.getInstance(configuration.getSaltAlgorithm());
    // Salt generation 64 bits long
    byte[] bSalt = new byte[8];
    random.nextBytes(bSalt);/* w ww.ja  va2  s .c om*/
    return Base64.encodeBase64String(bSalt);
}

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

public static String encrypt(String decryptedString, String password) {
    try {// ww w . j av  a  2  s . c om
        // build the initialization vector (randomly).
        SecureRandom random = new SecureRandom();
        byte initialVector[] = new byte[16];
        //generate random 16 byte IV AES is always 16bytes
        random.nextBytes(initialVector);
        IvParameterSpec ivspec = new IvParameterSpec(initialVector);
        SecretKeySpec skeySpec = new SecretKeySpec(password.getBytes("UTF-8"), "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
        byte[] encrypted = cipher.doFinal(decryptedString.getBytes());
        byte[] encryptedWithIV = new byte[encrypted.length + initialVector.length];
        System.arraycopy(encrypted, 0, encryptedWithIV, 0, encrypted.length);
        System.arraycopy(initialVector, 0, encryptedWithIV, encrypted.length, initialVector.length);
        return Base64.encodeBase64String(encryptedWithIV);
    } catch (Exception ex) {
        Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        return "Error";
    }
}

From source file:modelo.AutenticacionManager.Autenticacion.java

private static String encode(String sb) {
    return Base64.encodeBase64String(sb.getBytes());
}