Search in sources :

Example 36 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project candlepin by candlepin.

the class TestUtil method xmlToBase64String.

public static String xmlToBase64String(String xml) {
    // byte[] bytes = Base64.encode(xml);
    Base64 encoder = new Base64();
    byte[] bytes = encoder.encode(xml.getBytes());
    StringBuilder buf = new StringBuilder();
    for (byte b : bytes) {
        buf.append((char) Integer.parseInt(Integer.toHexString(b), 16));
    }
    return buf.toString();
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 37 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project coastal-hazards by USGS-CIDA.

the class FileHelper method base64Encode.

/**
 * Provides Base64 encoding and decoding as defined by <a
 * href="http://tools.ietf.org/html/rfc2045">RFC 2045</a>.
 *
 * @param input
 * @return Byte array representing the base 64 encoding of the incoming File
 * or byte array
 */
public static byte[] base64Encode(final byte[] input) {
    if (input == null) {
        return (byte[]) Array.newInstance(byte.class, 0);
    }
    log.trace(new StringBuilder("Attempting to base64 encode a byte array of ").append(input.length).append(" bytes.").toString());
    byte[] result = null;
    Base64 encoder = new Base64();
    result = encoder.encode(input);
    return result;
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 38 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project onebusaway-application-modules by camsys.

the class DigesterSignature method getDecodedValue.

public static String getDecodedValue(String key) {
    Base64 coder = new Base64();
    String encodedValue = key.substring(28);
    byte[] rawInput = coder.decode(encodedValue.getBytes());
    return new String(rawInput);
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 39 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class EnvelopePBETest method test1.

@Test
public void test1() throws Exception {
    Random random = new Random();
    for (int i = 1; i < 100; i++) {
        byte[] r = new byte[i];
        random.nextBytes(r);
        String password = new Base64(0).encodeToString(r);
        String encoded = EnvelopePBE.encode("PBKDF2WithHmacSHA1", 256, 4000, null, password);
        assertTrue(EnvelopePBE.check(encoded, password));
        assertFalse(EnvelopePBE.check(encoded, password + "A"));
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) Random(java.util.Random) Test(org.junit.Test)

Example 40 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class SsoUtils method generateAuthorizationToken.

public static String generateAuthorizationToken() {
    byte[] s = new byte[64];
    secureRandom.nextBytes(s);
    return new Base64(0, new byte[0], true).encodeToString(s);
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Aggregations

Base64 (org.apache.commons.codec.binary.Base64)149 IOException (java.io.IOException)33 Test (org.junit.Test)29 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)14 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 SecretKeySpec (javax.crypto.spec.SecretKeySpec)9 URL (java.net.URL)8 HashMap (java.util.HashMap)8 Cipher (javax.crypto.Cipher)8 File (java.io.File)7 MessageDigest (java.security.MessageDigest)7 Mac (javax.crypto.Mac)7 ServletException (javax.servlet.ServletException)7 FileNotFoundException (java.io.FileNotFoundException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 URLConnection (java.net.URLConnection)5