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

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

Introduction

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

Prototype

public Base64() 

Source Link

Document

Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

Usage

From source file:bazaar4idea.util.BzrErrorReportConfigurable.java

public String getPlainItnPassword() {
    if (AUTH_PASSWORD == null || "".equals(AUTH_PASSWORD.trim()))
        return "";
    return new String(new Base64().decode(AUTH_PASSWORD.getBytes()));
}

From source file:com.forsrc.utils.MyRsaUtils.java

/**
 * Encrypt string./*from   w  w  w  .j ava  2s  .c  o m*/
 *
 * @param rsaKey    the rsa key
 * @param plaintext the plaintext
 * @return the string
 */
public static String encrypt(RsaKey rsaKey, String plaintext) {
    BigInteger plaintextNumber = string2BigInteger(plaintext);
    BigInteger encrypt = encrypt(rsaKey, plaintextNumber);
    return new String(new Base64().encode(encrypt.toString().getBytes()));
}

From source file:com.socialize.oauth.signpost.signature.OAuthMessageSigner.java

private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();//  ww w  . j av a2s.  com
    this.base64 = new Base64();
}

From source file:com.aurel.track.beans.TBLOBBean.java

@Override
public ISerializableLabelBean deserializeBean(Map<String, String> attributes) {
    TBLOBBean blobBean = new TBLOBBean();
    String strObjectID = attributes.get("objectID");
    if (strObjectID != null) {
        blobBean.setObjectID(new Integer(strObjectID));
    }/*from w w w.java2s  .c  om*/
    String imageData = attributes.get("imageData");
    if (imageData != null) {
        byte[] byteArray = new Base64().decode(imageData);
        blobBean.setBLOBValue(byteArray);
    }
    blobBean.setUuid(attributes.get("uuid"));
    return blobBean;
}

From source file:com.wso2telco.identity.application.authentication.endpoint.util.TenantDataManager.java

private static synchronized void init() {

    try {//from  w w w .j a  v  a  2 s  .  c  o m
        if (!isInitialized) {
            prop = new Properties();

            InputStream inputStream = TenantDataManager.class.getClassLoader()
                    .getResourceAsStream("TenantConfig" + ".properties");

            if (inputStream != null) {
                prop.load(inputStream);

                usernameHeaderName = getPropertyValue(USERNAME_HEADER);

                carbonLogin = getPropertyValue(USERNAME);

                byte[] base64EncodedByteArray = new Base64().encode(carbonLogin.getBytes("UTF-8"));

                carbonLogin = new String(base64EncodedByteArray); //Base64 encode username

                String clientKeyStorePath = buildFilePath(getPropertyValue(CLIENT_KEY_STORE));
                String clientTrustStorePath = buildFilePath(getPropertyValue(CLIENT_TRUST_STORE));

                MutualSSLClient.loadKeyStore(clientKeyStorePath, getPropertyValue(CLIENT_KEY_STORE_PASSWORD));
                MutualSSLClient.loadTrustStore(clientTrustStorePath,
                        getPropertyValue(CLIENT_TRUST_STORE_PASSWORD));
                MutualSSLClient.initMutualSSLConnection();

                tenantDomainList = new ArrayList<String>();

                isInitialized = true;
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Configuration file TenantConfig.properties not found");
                }
            }
        }

    } catch (Exception e) {
        log.error("Initialization failed : ", e);
    }
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

public static String encodeToString(BufferedImage image) throws IOException {
    String imageString = "";
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {//from w w w  .j a v  a2  s . c  o  m
        Base64 encoder = new Base64();

        ImageIO.write(image, "png", bos);
        byte[] bytes = bos.toByteArray();

        imageString = BASE64_IMAGE_PNG + encoder.encodeToString(bytes);

    } finally {
        IOUtils.closeQuietly(bos);
    }
    return imageString;
}

From source file:com.intellij.diagnostic.ErrorReportConfigurable.java

public void setPlainItnPassword(String password) {
    ITN_PASSWORD_CRYPT = new String(new Base64().encode(password.getBytes()));
}

From source file:de.drop_converter.plugins.binary_convert.Base642Data.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {//from   w  w  w  .j a v  a2 s. c  o m
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, false);
                    out = getOutputStream(file, ".bin");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().decode(data.getBytes());
                out = getOutputStream(null, ".bin");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Data2Base64.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {//from  w w w .j av  a2s . c o  m
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, true);
                    out = getOutputStream(file, ".base64");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().encode(data.getBytes());
                out = getOutputStream(null, ".base64");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }

        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:com.vmware.admiral.auth.lightwave.pc.X509CertificateHelper.java

public String x509CertificateToBase64(X509Certificate x509Certificate) throws CertificateEncodingException {
    Base64 base64 = new Base64();

    return new String(base64.encode(x509Certificate.getEncoded()));
}