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.smartitengineering.cms.api.impl.content.OtherFieldValueImpl.java

@Override
protected String getValueAsString() {
    byte[] data = getValue();
    if (data != null) {
        return Base64.encodeBase64String(data);
    }//w  ww.  j  av a  2  s.c o m
    return super.getValueAsString();
}

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

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", "image/svg+xml");
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/docker-plain.svg")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));/*from   w  w  w . ja  v a  2  s. c  o  m*/
    return defaultGoPluginApiResponse;

}

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);//  w  w w. j  a v a  2 s  .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:com.commander4j.util.JCipher.java

public String encrypt(String plainText) throws Exception {
    Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
    byte[] encryptedBytes = cipher.doFinal(plainText.getBytes());

    return Base64.encodeBase64String(encryptedBytes);
}

From source file:de.adorsys.morphiaencryption.AES256CryptoProviderTest.java

@Test
public void testEncryptDecrypt() {
    String wrongKey = "4L3gj21IXIOnA7xzi0HF2g==";
    String encodeBase64Key = "Ie1imDDBddkhEqnUsntfsQ==";
    System.out.println(encodeBase64Key);
    AES256CryptoProvider aes256CryptoProvider = new AES256CryptoProvider(encodeBase64Key);

    String testText = "Dies ist ein im Zukunftsbild zu schtzender Text!";
    byte[] encrypted = aes256CryptoProvider.encrypt(testText.getBytes());
    System.out.println(Base64.encodeBase64String(encrypted));

    // neuen Crypto-Provider zum Entschlsseln erzeugen

    byte[] decrypted = aes256CryptoProvider.decrypt(encrypted);
    ;//w  w  w. j ava 2  s. c om
    System.out.println(new String(decrypted));
    Assert.assertEquals(testText, new String(decrypted));
    // Crypto-Provider mit abweichdendem Kennwort erzeugen
    try {
        new AES256CryptoProvider(wrongKey).decrypt(encrypted);
        Assert.fail("Fehler erwartet: Versuchte Entschlsselung mit abweichendem Key");
    } catch (CryptException e) {
        // o.k. erwartet
    }
}

From source file:com.ikanow.infinit.e.api.authentication.PasswordEncryption.java

/**
 *  Encrypt the password// w  w  w .j  a v a2  s . co m
 * @throws NoSuchAlgorithmException 
 * @throws UnsupportedEncodingException 
 */
public static String encrypt(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(password.getBytes("UTF-8"));
    return Base64.encodeBase64String(md.digest());
}

From source file:guru.nidi.loader.url.BasicAuthUrlLoader.java

public BasicAuthUrlLoader(String baseUrl, final String username, final String password,
        CloseableHttpClient httpClient) {
    super(baseUrl, new SimpleUrlFetcher() {
        @Override/*from  w  w w . j a v  a 2  s .  c  om*/
        protected HttpGet postProcessGet(HttpGet get) {
            get.addHeader("Authorization", encode(username, password));
            return get;
        }

        private String encode(String username, String password) {
            return Base64.encodeBase64String(
                    ("Basic " + username + ":" + password).getBytes(Charset.forName("iso-8859-1")));
        }
    }, httpClient);
}

From source file:it.latraccia.pkcs11.reader.util.AESUtil.java

public static String encryptString(String clearText, String password)
        throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
    String encrypted;// w ww.j a va  2 s .c  o  m
    byte[] key = password.getBytes();
    // Check the length of the password
    if (key.length != 16) {
        throw new IllegalArgumentException("Invalid password length.");
    }
    byte[] value = clearText.getBytes();

    // Encrypt with AES/CBC/PKCS5Padding
    SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(new byte[16]));
    byte[] encryptedBytes = cipher.doFinal(value);

    // Encode the bytes in base64
    encrypted = Base64.encodeBase64String(encryptedBytes);
    return encrypted;
}

From source file:fi.internetix.edelphi.taglib.chartutil.SvgImageHTMLEmitter.java

public String generateHTML() throws IOException, BirtException {
    byte[] chartData = ChartModelProvider.getChartData(chartModel, "SVG");

    StringBuilder dataUrlBuilder = new StringBuilder();
    dataUrlBuilder.append("data:image/svg+xml;base64,");
    dataUrlBuilder.append(Base64.encodeBase64String(chartData));

    StringBuilder html = new StringBuilder();
    html.append("<object type=\"image/svg+xml\"").append(" data=\"").append(dataUrlBuilder.toString())
            .append('"').append(" width=\"").append(width).append('"').append(" height=\"").append(height)
            .append('"').append(" style=\"display: block\"").append("></object>");
    return html.toString();
}

From source file:io.apicurio.hub.api.github.GitHubCreateBlob.java

/**
 * @param content the content to set/*from w ww.j  av a  2 s . c  om*/
 */
public void setContent(byte[] content) {
    this.content = Base64.encodeBase64String(content);
    this.encoding = "base64";
}