List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:de.jensd.addon.decoder.utils.ByteArray.java
public static String asBase64(byte[] payload) { return Base64.encodeBase64String(payload); }
From source file:edu.lternet.pasta.client.Escalator.java
public static String addGroup(String token, String group) { String[] tokenParts = token.split("-"); String authToken = new String(Base64.decodeBase64(tokenParts[0])); authToken += "*" + group; authToken = Base64.encodeBase64String(authToken.getBytes()); return authToken + "-" + tokenParts[1]; }
From source file:fr.free.divde.webcam.image.DataImageUrl.java
public static String imageToDataURL(BufferedImage image, String format, String mimeType) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(image, format, out); byte[] imageBytes = out.toByteArray(); String base64 = Base64.encodeBase64String(imageBytes); StringBuilder res = new StringBuilder("data:"); res.append(mimeType);/* w w w . j a va 2 s. c om*/ res.append(";base64,"); res.append(base64); return res.toString(); }
From source file:com.vico.license.util.rsa.RSAdoEncrypt.java
public static String encrypt(String source, byte[] publickey) throws Exception { String path = Thread.currentThread().getContextClassLoader().getResource("/").toURI().getPath(); Key publicKey = null;// w w w .ja va 2s . c om publicKey = (Key) ByteArrayToObj.ByteToObject(publickey); /** Cipher???RSA */ Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] b = source.getBytes("UTF-8"); /** ?*/ byte[] b1 = cipher.doFinal(b); String encryptedcode = Base64.encodeBase64String(b1); return encryptedcode; }
From source file:net.foreworld.util.RestUtil.java
public static String genSignature(String data, String key) { byte[] byteHMAC = null; try {//from w w w.j a va2 s.co m Mac mac = Mac.getInstance(ALGORITHM); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), ALGORITHM); mac.init(spec); byteHMAC = mac.doFinal(data.toLowerCase(Locale.getDefault()).getBytes()); } catch (InvalidKeyException ignore) { return null; } catch (NoSuchAlgorithmException ignore) { return null; } // END if (null == byteHMAC) return null; // String code = new BASE64Encoder().encode(byteHMAC); String code = Base64.encodeBase64String(byteHMAC); try { return URLEncoder.encode(code, ENC); } catch (UnsupportedEncodingException ignore) { } return null; }
From source file:com.saggezza.jtracker.track.PayloadMapC.java
private String base64encode(String string) throws UnsupportedEncodingException { Base64 b64 = new Base64(true); String safe_str = b64.encodeBase64String(string.getBytes(Charset.forName("US-ASCII"))); return safe_str; }
From source file:com.bytecode.util.Crypto.java
public static String encrypt256(String key, String message) throws Exception { return Base64.encodeBase64String(encrypt(key, message, BITS256)); }
From source file:net.orpiske.tcs.service.core.domain.Text.java
/** * Creates a new Text object out of a regular string. The data will be * compressed//from ww w . ja va2 s. c o m * @param string * @return */ public static Text fromString(final String string) throws IOException { byte[] compressedBytes = Compressor.compress(string); String encoded = Base64.encodeBase64String(compressedBytes); Text text = new Text(); text.setEncodedText(encoded); return text; }
From source file:it.paolorendano.clm.util.Utils.java
/** * Hash password./* ww w . j a v a 2 s . com*/ * * @param password the password * @return the string */ public static String hashPassword(String password) { MessageDigest mdigest; try { mdigest = MessageDigest.getInstance("SHA-256"); mdigest.update(password.getBytes("UTF-8")); return Base64.encodeBase64String(mdigest.digest()); } catch (NoSuchAlgorithmException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getMessage(), e); } catch (UnsupportedEncodingException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getMessage(), e); } return null; }
From source file:com.innoq.liqid.utils.SHACrypt.java
public static String encrypt(final String plaintext) { MessageDigest md = null;/*from w ww . ja v a2 s . c om*/ try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } try { md.update(plaintext.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } byte[] raw = md.digest(); return Base64.encodeBase64String(raw); }