Search in sources :

Example 31 with Base64.encodeBase64String

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

the class RssFeedServletTest method testInvalidAuthenticationRequest.

@Test
public void testInvalidAuthenticationRequest() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/feeds/unauthorized-repo");
    request.addHeader("User-Agent", "Apache Archiva unit test");
    request.setMethod("GET");
    Encoder encoder = new Base64();
    String userPass = "unauthUser:unauthPass";
    String encodedUserPass = new String((byte[]) encoder.encode(userPass.getBytes()));
    request.addHeader("Authorization", "BASIC " + encodedUserPass);
    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
    rssFeedServlet.doGet(request, mockHttpServletResponse);
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus());
}
Also used : Base64(org.apache.commons.codec.binary.Base64) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Encoder(org.apache.commons.codec.Encoder) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 32 with Base64.encodeBase64String

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

the class RssFeedServletTest method testRequestNewArtifactsInRepo.

@Test
public void testRequestNewArtifactsInRepo() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/feeds/test-repo");
    request.addHeader("User-Agent", "Apache Archiva unit test");
    request.setMethod("GET");
    Base64 encoder = new Base64(0, new byte[0]);
    String userPass = "user1:password1";
    String encodedUserPass = encoder.encodeToString(userPass.getBytes());
    request.addHeader("Authorization", "BASIC " + encodedUserPass);
    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
    rssFeedServlet.doGet(request, mockHttpServletResponse);
    assertEquals(RssFeedServlet.MIME_TYPE, mockHttpServletResponse.getHeader("CONTENT-TYPE"));
    assertNotNull("Should have recieved a response", mockHttpServletResponse.getContentAsString());
    assertEquals("Should have been an OK response code.", HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus());
}
Also used : Base64(org.apache.commons.codec.binary.Base64) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 33 with Base64.encodeBase64String

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

the class TestAuthFilterAuthOozieClient method computeSignature.

// Borrowed from org.apache.hadoop.security.authentication.util.Signer#computeSignature
private static String computeSignature(byte[] secret, String str) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(str.getBytes());
    md.update(secret);
    byte[] digest = md.digest();
    return new Base64(0).encodeToString(digest);
}
Also used : Base64(org.apache.commons.codec.binary.Base64) MessageDigest(java.security.MessageDigest)

Example 34 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project light-4j by networknt.

the class HashUtil method generateUUID.

public static String generateUUID() {
    UUID id = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(id.getMostSignificantBits());
    bb.putLong(id.getLeastSignificantBits());
    Base64 base64 = new Base64();
    return base64.encodeBase64URLSafeString(bb.array());
}
Also used : Base64(org.apache.commons.codec.binary.Base64) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 35 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project CBEC-B2B by A-Cubic.

the class Util method decryptBASE64.

public static byte[] decryptBASE64(String strBase64) throws Exception {
    Base64 base64 = new Base64();
    String newStr = strBase64.replaceAll("^(data:\\s*image\\/(\\w+);base64,)", "");
    // data:application/pdf;base64,
    byte[] debytes = base64.decode(newStr);
    return debytes;
// Decoder decoder = Base64.getDecoder();
// byte[] buffer = decoder.decode(newStr);
// return buffer;
}
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