List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.liaison.service.resources.examples.CodecResource.java
@ApiOperation(value = "decode", notes = "decodes base64 input string") @Path("/decode/{input}") @GET// w w w . j a va 2 s.c o m @Produces({ MediaType.APPLICATION_JSON }) public Response decode( @ApiParam(value = "a base64 string which is to be decoded", required = true) @PathParam("input") String input) { JSONObject response = new JSONObject(); try { // WARNING: USES DEFAULT ENCODING byte[] decoded = new Base64().decode(input.getBytes()); response.put("Decoded", new String(decoded)); return Response.ok(response.toString()).build(); } catch (Exception e) { logger.error("Error creating json response.", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:com.amalto.workbench.utils.PasswordUtil.java
public static String encryptPasswordBase64(String plainPassword) { Base64 base64 = new Base64(); byte[] enbytes = null; String encodeStr = null;/* ww w . j a va 2 s .co m*/ enbytes = base64.encode(plainPassword.getBytes()); encodeStr = new String(enbytes); return encodeStr; }
From source file:inti.core.codec.base64.Base64OutputStreamPerformanceTest.java
public void writePerformance(int count, int bufferSize) throws Exception { ByteArrayOutputStream underlying = new ByteArrayOutputStream(bufferSize); byte[] data;//from w w w . ja va 2 s . c o m long start, end; Base64 b64 = new Base64(); StringBuilder message = new StringBuilder(); for (int i = 0; i < bufferSize / 10; i++) { message.append("0123456789"); } data = message.toString().getBytes(Charset.forName("utf-8")); output.reset(underlying, null); for (int i = 0; i < 10; i++) { underlying.reset(); output.write(data); output.flush(); } for (int i = 0; i < 100; i++) { Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { underlying.reset(); output.write(data); output.flush(); } end = System.currentTimeMillis(); System.out.format("writePerformance(Inti) - size: %d, duration: %dms, ratio: %#.4f", bufferSize, end - start, count / ((end - start) / 1000.0)); System.out.println(); for (int i = 0; i < 10; i++) { b64.encode(data); } for (int i = 0; i < 100; i++) { Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { b64.encode(data); } end = System.currentTimeMillis(); System.out.format("writePerformance(commons.codec) - size: %d, duration: %dms, ratio: %#.4f", bufferSize, end - start, count / ((end - start) / 1000.0)); System.out.println(); }
From source file:com.ocpsoft.socialpm.util.crypt.MD5PasswordEncryptor.java
@Override public String encodePassword(final String password, final Object salt) { try {// w w w.j av a 2 s. c o m MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); digest.update(salt.toString().getBytes()); byte[] passwordHash = digest.digest(password.getBytes()); Base64 encoder = new Base64(); byte[] encoded = encoder.encode(passwordHash); return new String(encoded); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.quantil.http.HttpProcessor.java
private String createKey() throws Exception { SimpleDateFormat formatter;//from w w w.java 2s . c o m formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); currentDate = formatter.format(new Date()); SecretKeySpec signingKey = new SecretKeySpec(pass.getBytes(), "HmacSHA1"); // get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); // compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(currentDate.getBytes()); Base64 b64 = new Base64(); String pas = user + ":" + new String(b64.encode(rawHmac), "UTF-8"); return new String(b64.encode(pas.getBytes()), "UTF-8"); }
From source file:com.intellij.diagnostic.ErrorReportConfigurable.java
public String getPlainItnPassword() { return new String(new Base64().decode(ErrorReportConfigurable.getInstance().ITN_PASSWORD_CRYPT.getBytes())); }
From source file:com.alfaariss.oa.authentication.password.encode.Base64PwdEncoder.java
/** * @see IEncoder#getBytes(byte[])/* w w w.j a v a2 s. c o m*/ */ public byte[] getBytes(byte[] input) { Base64 b64 = new Base64(); return b64.encode(input); }
From source file:inti.core.codec.base64.Base64InputStreamPerformanceTest.java
public void readPerformance(int count, int bufferSize) throws Exception { byte[] data = new byte[bufferSize]; long start, end; StringBuilder message = new StringBuilder(); ByteArrayInputStream inputData; Base64 b64 = new Base64(); for (int i = 0; i < bufferSize / 10; i++) { message.append("0123456789"); }// w ww . j a v a 2 s.co m byte[] inputBytes = message.toString().getBytes(Charset.forName("utf-8")); inputData = new ByteArrayInputStream(inputBytes); for (int i = 0; i < 10; i++) { input.reset(inputData, null); inputData.reset(); input.read(data); } for (int i = 0; i < 100; i++) { Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { input.reset(inputData, null); inputData.reset(); input.read(data); } end = System.currentTimeMillis(); System.out.format("readPerformance(Inti) - size: %d, duration: %dms, ratio: %#.4f", bufferSize, end - start, count / ((end - start) / 1000.0)); System.out.println(); for (int i = 0; i < 10; i++) { b64.decode(inputBytes); } for (int i = 0; i < 100; i++) { Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { b64.decode(inputBytes); } end = System.currentTimeMillis(); System.out.format("readPerformance(commons.decode) - size: %d, duration: %dms, ratio: %#.4f", bufferSize, end - start, count / ((end - start) / 1000.0)); System.out.println(); }
From source file:license.mac.MacTest.java
/** * mac?//from w ww .j a v a 2 s .c o m * @return * @throws SocketException */ public boolean checkMac() throws SocketException { StringBuffer sb = new StringBuffer(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); int i = 12; Base64 base64 = new Base64(); for (NetworkInterface ni : Collections.list(interfaces)) { if (ni.getName().substring(0, 1).equalsIgnoreCase("e")) { sb.append(String.valueOf(i)).append('=').append(ni.getName()).append('\n'); i++; byte[] mac = ni.getHardwareAddress(); sb.append(String.valueOf(i)).append('=').append(base64.encodeAsString(mac)).append('\n'); i++; } } System.out.println(sb.toString()); return true; }
From source file:cfa.vo.interop.EncodeDoubleArray.java
public static double[] decodeBase64(String dataString, boolean swapByteOrder) throws IOException { byte[] encodedData = dataString.getBytes(); Base64 codec = new Base64(); byte[] decodedData = codec.decode(encodedData); if (swapByteOrder) { ByteBuffer buf = ByteBuffer.wrap(decodedData); buf = buf.order(ByteOrder.LITTLE_ENDIAN); buf.get(decodedData);/*from w ww.j a v a 2 s .c om*/ } double[] result = byteToDouble(decodedData); return result; }