Search in sources :

Example 81 with Base64.encodeBase64String

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

the class Base64DataFormat method marshalUrlSafe.

private void marshalUrlSafe(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    byte[] decoded = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, graph);
    Base64 codec = new Base64(lineLength, lineSeparator, true);
    byte[] encoded = codec.encode(decoded);
    stream.write(encoded);
    stream.flush();
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 82 with Base64.encodeBase64String

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

the class DigestOfFile method digestAsBase64.

/**
     * @author rlemeill
     * @param file
     * @return hash (base64 encoded)
     * @throws Exception
     */
public synchronized String digestAsBase64(File file) throws Exception {
    byte[] digest = digestAsByteArray(file);
    Base64 encoder = new Base64();
    String digestAsBase64 = new String(encoder.encode(digest), "ASCII");
    return digestAsBase64;
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 83 with Base64.encodeBase64String

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

the class Response method loadXmlFromBase64.

public void loadXmlFromBase64(String response) throws ParserConfigurationException, SAXException, IOException {
    Base64 base64 = new Base64();
    byte[] decodedResponse = base64.decode(response);
    String decodedS = new String(decodedResponse);
    loadXml(decodedS);
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 84 with Base64.encodeBase64String

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

the class DigestPasswordLoginModule method doPasswordDigest.

public String doPasswordDigest(String nonce, String created, byte[] password) {
    String passwdDigest = null;
    try {
        byte[] b1 = nonce != null ? new Base64().decode(nonce) : new byte[0];
        byte[] b2 = created != null ? created.getBytes("UTF-8") : new byte[0];
        byte[] b3 = password;
        byte[] b4 = new byte[b1.length + b2.length + b3.length];
        int offset = 0;
        System.arraycopy(b1, 0, b4, offset, b1.length);
        offset += b1.length;
        System.arraycopy(b2, 0, b4, offset, b2.length);
        offset += b2.length;
        System.arraycopy(b3, 0, b4, offset, b3.length);
        byte[] digestBytes = generateDigest(b4);
        passwdDigest = new String(new Base64().encodeBase64(digestBytes));
    } catch (Exception e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return passwdDigest;
}
Also used : Base64(org.apache.commons.codec.binary.Base64) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 85 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nhin-d by DirectProject.

the class LdapCertUtilImpl_LdapSearch_Test method testCertificateFormatIsX509_CertificateIsAddedCorrectly.

/**
	 * 
	 * @throws Exception
	 */
public void testCertificateFormatIsX509_CertificateIsAddedCorrectly() throws Exception {
    new TestPlan() {

        protected Object nextElement_Internal() {
            BufferedInputStream f = null;
            try {
                File fl = new File("testfile");
                int idx = fl.getAbsolutePath().lastIndexOf("testfile");
                String path = fl.getAbsolutePath().substring(0, idx);
                byte[] buffer = new byte[(int) new File(path + "src/test/resources/certs/bob.der").length() + 100];
                f = new BufferedInputStream(new FileInputStream(path + "src/test/resources/certs/bob.der"));
                f.read(buffer);
                Base64 base64 = new Base64();
                theNextElement = new String(base64.encode(buffer));
            } catch (Exception e) {
                e.printStackTrace();
                fail();
                IOUtils.closeQuietly(f);
            }
            return theNextElement;
        }

        protected String createCertificateFormat() {
            theCreateCertificateFormat = "X509";
            return theCreateCertificateFormat;
        }

        protected void doAssertions(Collection<X509Certificate> ldapSearch) throws Exception {
            assertEquals(1, nextElementCalls);
            assertNotNull(ldapSearch);
            assertEquals(1, ldapSearch.size());
            X509Certificate cert = ldapSearch.iterator().next();
            assertTrue(cert instanceof X509Certificate);
            assertEquals("EMAILADDRESS=bob@nhind.hsgincubator.com, CN=Bob Patel, OU=Incubator, O=HSG, L=Redmond, ST=WA, C=US", cert.getSubjectX500Principal().toString());
        }
    }.perform();
}
Also used : Base64(org.apache.commons.codec.binary.Base64) BaseTestPlan(org.nhindirect.stagent.utils.BaseTestPlan) BufferedInputStream(java.io.BufferedInputStream) String(java.lang.String) File(java.io.File) FileInputStream(java.io.FileInputStream) KeyStoreException(java.security.KeyStoreException) NamingException(javax.naming.NamingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

Base64 (org.apache.commons.codec.binary.Base64)135 IOException (java.io.IOException)30 Test (org.junit.Test)29 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 InputStream (java.io.InputStream)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 HashMap (java.util.HashMap)10 SecretKeySpec (javax.crypto.spec.SecretKeySpec)9 MessageDigest (java.security.MessageDigest)8 File (java.io.File)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 URL (java.net.URL)7 Mac (javax.crypto.Mac)7 ServletException (javax.servlet.ServletException)7 X509Certificate (java.security.cert.X509Certificate)6 FileNotFoundException (java.io.FileNotFoundException)5 Signature (java.security.Signature)5