List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:com.wabacus.util.DesEncryptTools.java
private static String base64Encode(byte[] b) { if (b == null) return null; try {/*from w ww. j a v a 2s. co m*/ return Base64.encodeBase64String(b); } catch (Exception e) { e.printStackTrace(); return null; } // try // return null; }
From source file:com.comcast.video.dawg.show.video.BufferedImageCerealizer.java
/** * {@inheritDoc}/*from w ww .ja va2 s . co m*/ */ @Override public String cerealize(BufferedImage object, ObjectCache objectCache) throws CerealException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { try { ImageIO.write(object, "jpg", baos); } catch (IOException e) { throw new CerealException("Failed to cerealize BufferedImage", e); } return Base64.encodeBase64String(baos.toByteArray()); } finally { IOUtils.closeQuietly(baos); } }
From source file:com.streamsets.lib.security.http.TestPlainSSOTokenParser.java
protected String encodeToken(SSOUserPrincipal principal) throws Exception { return Base64.encodeBase64String(new ObjectMapper().writeValueAsString(principal).getBytes()); }
From source file:com.eviware.loadui.util.testevents.TestEventSourceSupport.java
private void updateHash() { byte[] labelBytes = label.getBytes(); byte[] combined = new byte[labelBytes.length + data.length]; System.arraycopy(labelBytes, 0, combined, 0, labelBytes.length); System.arraycopy(data, 0, combined, labelBytes.length, data.length); hash = Base64.encodeBase64String(DigestUtils.md5(combined)); }
From source file:io.druid.indexing.overlord.WorkerSetupDataTest.java
@Test public void testStringEC2UserDataSerde() throws IOException { final String json = "{\"impl\":\"string\",\"data\":\"hey :ver:\",\"versionReplacementString\":\":ver:\",\"version\":\"1234\"}"; final StringEC2UserData userData = (StringEC2UserData) TestUtils.MAPPER.readValue(json, EC2UserData.class); Assert.assertEquals("hey :ver:", userData.getData()); Assert.assertEquals("1234", userData.getVersion()); Assert.assertEquals(Base64.encodeBase64String("hey 1234".getBytes(Charsets.UTF_8)), userData.getUserDataBase64()); Assert.assertEquals(Base64.encodeBase64String("hey xyz".getBytes(Charsets.UTF_8)), userData.withVersion("xyz").getUserDataBase64()); }
From source file:com.hyeb.back.login.LoginController.java
/** * // w ww.j av a 2 s . c o m */ @RequestMapping(value = "/login") public String login(ModelMap model, RedirectAttributes redirectAttributes, HttpServletRequest request) { /** "?"??? */ final String PRIVATE_KEY_ATTRIBUTE_NAME = "privateKey"; //HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); Setting setting = SettingUtils.get(); KeyPair keyPair = RSAUtils.generateKeyPair(); RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); request.getSession().setAttribute(PRIVATE_KEY_ATTRIBUTE_NAME, privateKey); String modulus = Base64.encodeBase64String(publicKey.getModulus().toByteArray());//N String exponent = Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray());//e String captchaId = UUID.randomUUID().toString(); boolean isBackCaptcha = ArrayUtils.contains(setting.getCaptchaTypes(), CaptchaType.adminLogin); model.addAttribute("modulus", modulus); model.addAttribute("exponent", exponent); model.addAttribute("captchaId", captchaId); model.addAttribute("isBackCaptcha", isBackCaptcha); String messageStr = null; String loginFailure = (String) request .getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if (loginFailure != null) { if (loginFailure.equals("org.apache.shiro.authc.pam.UnsupportedTokenException")) {//?? messageStr = "admin.captcha.invalid"; } else if (loginFailure.equals("org.apache.shiro.authc.UnknownAccountException")) {// messageStr = "admin.login.unknownAccount"; } else if (loginFailure.equals("org.apache.shiro.authc.DisabledAccountException")) {//? messageStr = "admin.login.disabledAccount";// } else if (loginFailure.equals("org.apache.shiro.authc.LockedAccountException")) {//? messageStr = "admin.login.lockedAccount"; } else if (loginFailure.equals("org.apache.shiro.authc.IncorrectCredentialsException")) {//?? if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { messageStr = "admin.login.accountLockCount";//?{0}??? } else { messageStr = "admin.login.incorrectCredentials";//??? } } else if (loginFailure.equals("org.apache.shiro.authc.AuthenticationException")) {// messageStr = "admin.login.authentication";//?? } if (messageStr != null) { Message message = Message.warn(messageStr); addFlashMessage(redirectAttributes, message); } } Subject subject = SecurityUtils.getSubject(); if (subject.isAuthenticated()) { return "redirect:/back/main/main"; } else { return "/back/login/login"; } }
From source file:com.adobe.acs.commons.http.impl.HttpClientFactoryImplTest.java
@Before public void setup() throws Exception { config = new HashMap<String, Object>(); username = RandomStringUtils.randomAlphabetic(5); password = RandomStringUtils.randomAlphabetic(6); final String authHeaderValue = Base64.encodeBase64String((username + ":" + password).getBytes()); config.put("hostname", "localhost"); config.put("port", mockServerRule.getPort().intValue()); mockServerClient.when(request().withMethod("GET").withPath("/anon")) .respond(response().withStatusCode(200).withBody("OK")); mockServerClient.when(request().withMethod("GET").withPath("/anonJson")) .respond(response().withStatusCode(200).withBody("{ 'foo' : 'bar' }")); mockServerClient.when(request().withMethod("GET").withPath("/auth").withHeader("Authorization", "Basic " + authHeaderValue)).respond(response().withStatusCode(200).withBody("OK")); impl = new HttpClientFactoryImpl(); PrivateAccessor.setField(impl, "httpClientBuilderFactory", new HttpClientBuilderFactory() { @Override//from w w w. ja v a 2 s . c o m public HttpClientBuilder newBuilder() { return HttpClients.custom(); } }); }
From source file:com.dp2345.controller.mall.CommonController.java
/** * //w ww .ja va 2 s. c om */ @RequestMapping(value = "/public_key", method = RequestMethod.GET) public @ResponseBody Map<String, String> publicKey(HttpServletRequest request) { RSAPublicKey publicKey = rsaService.generateKey(request); Map<String, String> data = new HashMap<String, String>(); data.put("modulus", Base64.encodeBase64String(publicKey.getModulus().toByteArray())); data.put("exponent", Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray())); return data; }
From source file:com.sisfin.util.CryptService.java
/** * Codifica uma palavra para um formato de hash Base64. Utilizado para * criptografar senhas./* w ww .j a va2 s . c o m*/ * * @param input * a palavra a ser codificada para hash * @return uma string Base64 representando o hash * @throws IllegalArgumentException * lana esta exceo se a palavra de entrada nula */ public String hash(String input) throws IllegalArgumentException { if (input == null) { throw new IllegalArgumentException("A entrada no pode ser nula."); } byte[] out = md.digest(input.getBytes()); return Base64.encodeBase64String(out); }
From source file:com.imagesleuth.imagesleuthclient2.Getter.java
public Getter(String url, String user, String password) { Test.testNull(url);/* w ww. j ava 2s . co m*/ Test.testNull(user); Test.testNull(password); this.url = url; harray.add(new BasicHeader("Authorization", "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes()))); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); credsProvider.setCredentials(AuthScope.ANY, credentials); requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(30000).build(); }