List of usage examples for java.util Base64 getEncoder
public static Encoder getEncoder()
From source file:ninja.eivind.hotsreplayuploader.window.nodes.BattleLobbyNode.java
public String base64EncodeBattleLobby(Replay replay) { Base64.Encoder encoder = Base64.getEncoder(); List<String> asString = replay .getReplayDetails().getPlayers().stream().map(player -> player.getBattleNetRegionId() + "#" + player.getShortName() + "#" + player.getBattleTag() + "#" + player.getTeam()) .collect(Collectors.toList()); try {/* ww w. j av a2 s . c om*/ byte[] data = String.join(",", asString).getBytes("UTF-8"); return encoder.encodeToString(data); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Search.DataManipulation.DataParser.java
public String getThumbnails(Document dom) throws IOException { Elements thumbnailsClass = dom.getElementsByClass("thumbnails"); Elements thumbnails = thumbnailsClass.first().children(); List<String> imageArray = new ArrayList<String>(); for (Element images : thumbnails) { String imageTagUrl = images.getElementsByTag("img").first().attr("src"); byte[] imageByte = dataHandler.imageDownloader(imageTagUrl); if (imageByte.length == 0) { continue; }/*from w w w . j ava2s .c o m*/ String imageTag = Base64.getEncoder().encodeToString(imageByte); imageArray.add(imageTag); } return JSONValue.toJSONString(imageArray); }
From source file:com.devicehive.base.AbstractResourceTest.java
protected String basicAuthHeader(String login, String password) { String str = String.format("%s:%s", login, password); String base64 = Base64.getEncoder().encodeToString(str.getBytes()); return String.format("Basic %s", base64); }
From source file:net.straylightlabs.archivo.model.Tivo.java
/** * Convert this Tivo to a JSON object./* ww w .j a v a 2s . com*/ * * @return A new JSONObject representing this Tivo */ public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put(JSON_NAME, name); json.put(JSON_TSN, tsn); json.put(JSON_PORT, port); Base64.Encoder encoder = Base64.getEncoder(); String[] encodedAddresses = new String[addresses.size()]; Iterator<InetAddress> iterator = addresses.iterator(); int i = 0; while (iterator.hasNext()) { encodedAddresses[i] = encoder.encodeToString(iterator.next().getAddress()); i++; } json.put(JSON_ADDRESSES, new JSONArray(encodedAddresses)); return json; }
From source file:sh.isaac.provider.sync.git.gitblit.utils.ConnectionUtils.java
/** * Set authorization./*from w ww . j av a 2 s .co m*/ * * @param conn the conn * @param username the username * @param password the password */ public static void setAuthorization(URLConnection conn, String username, char[] password) { if (!StringUtils.isEmpty(username) && ((password != null) && (password.length > 0))) { conn.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString( toBytes(ArrayUtils.addAll(new String(username + ":").toCharArray(), password)))); } }
From source file:waffle.spring.ImpersonateTests.java
/** * Test impersonate enabled.// www . j a v a 2 s. c om * * @throws IOException * Signals that an I/O exception has occurred. * @throws ServletException * the servlet exception */ @Test public void testImpersonateEnabled() throws IOException, ServletException { Assertions.assertNotEquals("Current user shouldn't be the test user prior to the test", MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName()); final SimpleHttpRequest request = new SimpleHttpRequest(); request.setMethod("GET"); final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD; final String basicAuthHeader = "Basic " + Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8)); request.addHeader("Authorization", basicAuthHeader); final SimpleHttpResponse response = new SimpleHttpResponse(); final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain(); this.filter.setImpersonate(true); this.filter.doFilter(request, response, filterChain); final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Assertions.assertTrue(authentication.isAuthenticated(), "Test user should be authenticated"); final Principal principal = (Principal) authentication.getPrincipal(); assertThat(principal).isInstanceOf(AutoDisposableWindowsPrincipal.class); final AutoDisposableWindowsPrincipal windowsPrincipal = (AutoDisposableWindowsPrincipal) principal; try { Assertions.assertEquals(MockWindowsAccount.TEST_USER_NAME, filterChain.getUserName(), "Test user should be impersonated"); Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName(), "Impersonation context should have been reverted"); } finally { windowsPrincipal.getIdentity().dispose(); } }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint.java
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; // compute a nonce (do not use remote IP address due to proxy farms) // format of nonce is: // base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key)) long expiryTime = System.currentTimeMillis() + (nonceValiditySeconds * 1000); String signatureValue = DigestAuthUtils.md5Hex(expiryTime + ":" + key); String nonceValue = expiryTime + ":" + signatureValue; String nonceValueBase64 = new String(Base64.getEncoder().encode(nonceValue.getBytes())); // qop is quality of protection, as defined by RFC 2617. // we do not use opaque due to IE violation of RFC 2617 in not // representing opaque on subsequent requests in same session. String authenticateHeader = "Digest realm=\"" + realmName + "\", " + "qop=\"auth\", nonce=\"" + nonceValueBase64 + "\""; if (authException instanceof NonceExpiredException) { authenticateHeader = authenticateHeader + ", stale=\"true\""; }/* ww w. j a v a 2 s .c o m*/ if (logger.isDebugEnabled()) { logger.debug("WWW-Authenticate header sent to user agent: " + authenticateHeader); } httpResponse.addHeader("WWW-Authenticate", authenticateHeader); httpResponse.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase()); }
From source file:org.codice.alliance.distribution.branding.AllianceBrandingPluginTest.java
@Test public void testVendorImage() throws IOException { allianceBrandingPlugin.init();//from w w w . j a v a 2 s .com assertThat(allianceBrandingPlugin.getBase64VendorImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(AllianceBrandingPluginTest.class.getResourceAsStream(vendorImage)))))); }
From source file:org.codice.alliance.distribution.branding.TestAllianceBrandingPlugin.java
@Test public void testVendorImage() throws IOException { allianceBrandingPlugin.init();//from w ww.j av a2 s . c o m assertThat(allianceBrandingPlugin.getBase64VendorImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(TestAllianceBrandingPlugin.class.getResourceAsStream(vendorImage)))))); }
From source file:io.stallion.services.SecureTempTokens.java
public String idToRandomString(Long id) { SecureRandom random = new SecureRandom(); Integer rand = random.nextInt(); Long n = rand * 1000000000 + id; return Base64.getEncoder().encodeToString(BigInteger.valueOf(n).toByteArray()); }