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:net.sourceforge.jaulp.crypto.sha.Hasher.java

public static String hashAndBase64(String hashIt, String salt, HashAlgorithm hashAlgorithm, Charset charset)
        throws NoSuchAlgorithmException {
    String hashedAndBase64 = new Base64()
            .encodeToString(hash(hashIt, salt, hashAlgorithm, charset).getBytes(charset));
    return hashedAndBase64;
}

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

/**
 * Big integer 2 string string.// ww w  .jav  a 2s  . co  m
 *
 * @param bigInteger the big integer
 * @return the string
 * @throws IOException the io exception
 */
public static String bigInteger2String(BigInteger bigInteger) throws IOException {

    return new String(new Base64().decode(toStr(bigInteger)));
}

From source file:be.wolkmaan.klimtoren.security.digest.StandardStringDigester.java

public StandardStringDigester() {
    super();//from ww w.  ja  va 2  s.  c  o  m
    this.byteDigester = new StandardByteDigester();
    this.base64 = new Base64();
}

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

/**
 * Encrypt string.//from  w  w w. ja  v  a 2s  .c o m
 *
 * @param aes the aes
 * @param src the src
 * @return String string
 * @throws AesException the aes exception
 * @Title: encrypt
 * @Description:
 */
public static String encrypt(AesKey aes, String src) throws AesException {

    byte[] encrypted = null;
    try {
        encrypted = aes.getEncryptCipher().doFinal(src.getBytes(CHARSET_UTF8));
    } catch (IllegalBlockSizeException e) {
        throw new AesException(e);
    } catch (BadPaddingException e) {
        throw new AesException(e);
    } catch (UnsupportedEncodingException e) {
        throw new AesException(e);
    }
    return new String(new Base64().encode(encrypted));
}

From source file:com.trsst.client.MultiPartRequestEntity.java

private static void writeContent(byte[] content, String contentId, String contentType, DataOutputStream out)
        throws IOException {
    if (contentType == null) {
        throw new NullPointerException("media content type can't be null");
    }//from  w w  w  .  jav  a2 s.  c o  m
    out.writeBytes("content-type: " + contentType + "\r\n");
    out.writeBytes("content-id: <cid:" + contentId + ">\r\n\r\n");
    out.write(new Base64().encode(content));
}

From source file:com.credomatic.gprod.db2query2csv.Security.java

/**
 * Descifra una cadena de caracteres apartir de la llave de cifrado y retorna le valor original.
 * @param key llave generada durante el cifrado de la cadena original
 * @param value cadena cifrda/*from   ww w  .j  a v  a 2 s.c om*/
 * @return cadena descifrada
 */
public static String decrypt(String key, String value) {
    try {
        Key k = new SecretKeySpec(new Base64().decode(key), "AES");
        Cipher c = Cipher.getInstance("AES");
        c.init(Cipher.DECRYPT_MODE, k);
        byte[] decodedValue = new Base64().decode(value);
        byte[] decValue = c.doFinal(decodedValue);
        String decryptedValue = new String(decValue);
        return decryptedValue;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
            | BadPaddingException ex) {
        Logger.getLogger(Security.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:license.regist.ReadProjectInfo.java

private static boolean checkMac(Map<Integer, String> infoMap) throws SocketException {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    Base64 base64 = new Base64();
    int i = 12;/*from  w w w  .j  a  v a  2s .c o  m*/
    for (NetworkInterface ni : Collections.list(interfaces)) {
        if (ni.getName().substring(0, 1).equalsIgnoreCase("e")) {
            if (!((String) infoMap.get(Integer.valueOf(i))).equalsIgnoreCase(ni.getName()))
                return false;
            i++;
            byte[] mac = ni.getHardwareAddress();

            if (!((String) infoMap.get(Integer.valueOf(i))).equalsIgnoreCase(base64.encodeAsString(mac))) {
                return false;
            }
            i++;
        }
    }
    return true;
}

From source file:com.liaison.service.resources.examples.CodecResource.java

@ApiOperation(value = "encode", notes = "encodes value as base64 input string")
@Path("/encode/{input}")
@GET/* ww  w .ja  v  a2 s. co m*/
@Produces({ MediaType.APPLICATION_JSON })
public Response encode(
        @ApiParam(value = "a value which is to be encoded as base64", required = true) @PathParam("input") String input) {

    JSONObject response = new JSONObject();
    try {
        // WARNING:  USES DEFAULT ENCODING
        byte[] encoded = new Base64().encode(input.getBytes());
        response.put("Encoded", new String(encoded));
        return Response.ok(response.toString()).build();
    } catch (Exception e) {
        logger.error("Error creating json response.", e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:HttpClient1.java

private void setAuthorization() {
    try {//from   www .  j  a  v  a 2s  .  com
        httpConn = (HttpURLConnection) url.openConnection();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    userpass = prop.getProperty("user") + ":" + prop.getProperty("password");
    basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
    httpConn.setRequestProperty("Authorization", basicAuth);
}

From source file:io.hawt.web.JBossPostApp.java

@Test
public void testPostWithAuthorizationHeader() throws Exception {
    System.out.println("Using URL: " + url + " user: " + userName + " password: " + password);

    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(url);

    String userPwd = userName + ":" + password;
    String hash = new Base64().encodeAsString(userPwd.getBytes());
    method.setRequestHeader("Authorization", "Basic " + hash);
    System.out.println("headers " + Arrays.asList(method.getRequestHeaders()));
    method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8"));

    int result = client.executeMethod(method);

    System.out.println("Status: " + result);

    String response = method.getResponseBodyAsString();
    System.out.println(response);
}