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

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

Introduction

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

Prototype

public static byte[] encodeBase64(final byte[] binaryData) 

Source Link

Document

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

Usage

From source file:net.sf.sripathi.ws.mock.util.WebServiceutil.java

/**
 * Invokes the web service using SAAJ API.
 * //from w w w.ja va 2 s  .com
 * @param request soap request string.
 * @param url end point URL.
 * @param user user name for authentication.
 * @param password password for authentication.
 * 
 * @return response soap string.
 */
public static String callWebService(String request, String url, String user, String password) {

    if (request == null)
        request = "";
    try {
        SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();

        MimeHeaders hd = new MimeHeaders();
        hd.addHeader("Content-Type", "text/xml");
        if (StringUtil.isValid(user) && StringUtil.isValid(password)) {
            String authorization = new String(Base64.encodeBase64((user + ":" + password).getBytes()));
            hd.addHeader("Authorization", "Basic " + authorization);
        }

        SOAPMessage msg = MessageFactory.newInstance().createMessage(hd,
                new ByteArrayInputStream(request.getBytes()));
        SOAPMessage resp = conn.call(msg, url);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        resp.writeTo(baos);
        return new String(baos.toByteArray());
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        return sw.toString();
    }
}

From source file:com.google.code.mymon3y.util.Hasher.java

/**
 * Retorna o hash SHA 256 da string./*from   w  ww .  j  a  va  2 s .c  om*/
 * 
 * @param string
 *            String a ser avaliada.
 * @return O hash SHA 256 da string.
 */
public static String getSha256(String string) {

    if (string == null || string.equals("")) {
        return string;
    }

    String senhaEncriptada = null;

    byte[] hash = md.digest(string.getBytes());
    senhaEncriptada = new String(Base64.encodeBase64(hash));

    return senhaEncriptada;
}

From source file:de.uzk.hki.da.passwordEncryptor.passwordEncryptor.java

private static String encryptPasswordForContentBroker(String password) {

    byte key[] = "394z57f4".getBytes();
    byte encryptedPassword[];

    try {//from   ww w .ja  v  a 2s. c o  m
        SecretKey secretKey = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(key));

        Cipher encrypt = Cipher.getInstance("DES/CBC/PKCS5Padding");
        encrypt.init(Cipher.ENCRYPT_MODE, secretKey,
                new IvParameterSpec(new byte[] { 0x01, 0x02, 0x04, 0x10, 0x01, 0x02, 0x04, 0x10 }));
        encryptedPassword = encrypt.doFinal(password.getBytes());
    } catch (GeneralSecurityException e) {
        throw new RuntimeException("Couldn't encrypt password " + password + e);
    }

    return new String(Base64.encodeBase64(encryptedPassword));
}

From source file:com.agiletec.aps.util.DefaultApsEncrypter.java

public static String encryptString(String plainText) throws ApsSystemException {
    String encryptedString = null;
    try {//w  w w.  jav a  2s .c om
        Key key = getKey();
        Cipher desCipher = Cipher.getInstance(TRIPLE_DES);
        desCipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] cleartext = plainText.getBytes();
        byte[] ciphertext = desCipher.doFinal(cleartext);
        encryptedString = new String(Base64.encodeBase64(ciphertext));
    } catch (Throwable t) {
        throw new ApsSystemException("Error detcted while encoding a string", t);
    }
    return encryptedString;
}

From source file:io.cloudslang.content.azure.services.AuthorizationTokenImpl.java

@NotNull
public static String getToken(@NotNull final String identifier, @NotNull final String primaryOrSecondaryKey,
        @NotNull final Date expiryDate) {
    final Mac sha512Hmac = HmacUtils.getHmacSha512(primaryOrSecondaryKey.getBytes(UTF_8));
    final String dataToSign = String.format("%s\n%s", identifier, DateUtilities.formatDate(expiryDate));
    final byte[] encodedBytes = Base64.encodeBase64(sha512Hmac.doFinal(dataToSign.getBytes(UTF_8)));
    final String encodedString = new String(encodedBytes, UTF_8);
    return String.format(SHARED_ACCESS_SIGNATURE, identifier, DateUtilities.formatDate(expiryDate),
            encodedString);/*w w  w .  j a  v a 2  s .c om*/
}

From source file:com.evolveum.midpoint.util.SerializationUtil.java

public static String toString(Object object) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(object);
    objectOutputStream.close();/*from   www. j a  va2 s  .co m*/
    return new String(Base64.encodeBase64(byteArrayOutputStream.toByteArray()));
}

From source file:com.itemanalysis.jmetrik.workspace.JmetrikPassword.java

public String encodePassword(String pw) {
    byte[] encodedBytes = Base64.encodeBase64(StringUtils.getBytesUtf8(pw));
    String encodedContent = StringUtils.newStringUtf8(encodedBytes);
    return encodedContent;
}

From source file:com.useekm.types.GeoWkb.java

public GeoWkb(Geometry geometry) {
    super(new String(Base64.encodeBase64(new WKBWriter().write(geometry))));
    Validate.notNull(geometry);
}

From source file:com.useekm.types.GeoWkbGz.java

public GeoWkbGz(Geometry geometry) {
    super(new String(Base64.encodeBase64(gzip(new WKBWriter().write(geometry)))));
    Validate.notNull(geometry);
}

From source file:com.useekm.types.GeoWktGz.java

public GeoWktGz(Geometry geometry) {
    super(new String(Base64.encodeBase64(gzip(new WKTWriter().write(geometry).getBytes()))));
    Validate.notNull(geometry);// ww w  .jav  a  2  s  .  co m
}