List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.cloudera.recordservice.mr.security.TokenUtils.java
/** * Encodes the byte array as a string.//from w w w.java 2 s. c om */ public static String encodeAsString(byte[] v) { return new String(Base64.encodeBase64(v)); }
From source file:com.greenpepper.server.license.LicenceGenerator.java
private static void buildOpenSource() throws Exception { File file = File.createTempFile("opensource", ".lic"); License license = License.openSource("My Open Source Project", _2006, _2006); LicenseManager lm = new LicenseManager(getLicenseParam()); lm.store(license, file);// ww w . java 2s . co m if (deleteFiles) file.deleteOnExit(); System.out.println("# Open source"); System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file)))); System.out.println(""); }
From source file:com.janrain.backplane.common.HmacHashUtils.java
/** * @return HMAC hash, or null if the supplied password is null or the hash could not be computed *//*w w w. j a va2 s . c o m*/ public static String hmacHash(String password) { try { if (password == null) return null; SecretKey key = generateMacKey(HMAC_SHA256_ALGORITHM, HMAC_SHA256_LENGTH); byte[] encoded = key.getEncoded(); if (encoded == null) { logger.error("Mac key encoding is null, cannot hash password."); return null; } return new String(Base64.encodeBase64(encoded), UTF8_STRING_ENCODING) + "." + hmacSign(key, password); } catch (Exception e) { logger.error("Error computing HMAC hash: " + e.getMessage()); return null; } }
From source file:com.inmobi.messaging.consumer.util.MessageUtil.java
public static void createMessageFile(String fileName, FileSystem fs, Path parent, int msgIndex) throws IOException { FSDataOutputStream out = fs.create(new Path(parent, fileName)); for (int i = 0; i < 100; i++) { out.write(Base64.encodeBase64(constructMessage(msgIndex).getBytes())); out.write('\n'); msgIndex++;/* ww w . ja v a2 s. com*/ } out.close(); TestUtil.LOG.debug("Created data file:" + new Path(parent, fileName)); }
From source file:com.amazonaws.cognito.devauthsample.AESEncryption.java
/** * Encrypt a string with a given key.//from www . j a v a 2s .com * * @param clearText string to be encrypted * @param key encryption key * @return encrypted string */ public static String wrap(String clearText, String key) { byte[] iv = getIv(); byte[] cipherText = encrypt(clearText, key, iv); byte[] wrapped = new byte[iv.length + cipherText.length]; System.arraycopy(iv, 0, wrapped, 0, iv.length); System.arraycopy(cipherText, 0, wrapped, 16, cipherText.length); return new String(Base64.encodeBase64(wrapped)); }
From source file:de.bayern.gdi.utils.StringUtils.java
/** * Encodes user name and password into base64 encoded string. * @param user The user name./*from w w w . java 2 s.c o m*/ * @param password The passord. * @return The encoded password. null if user or password is null. */ public static String getBase64EncAuth(String user, String password) { if (user == null || password == null) { return null; } String auth = user + ":" + password; return new String(Base64.encodeBase64(auth.getBytes())); }
From source file:mitm.common.util.Base64Utils.java
/** * Base64 encodes the input//from ww w . jav a2 s . com */ public static String encode(byte[] data) { return MiscStringUtils.toAsciiString(Base64.encodeBase64(data)); }
From source file:com.alibaba.otter.shared.common.utils.ByteUtils.java
public static String bytesToBase64String(byte[] bytes) { try {//from w w w. java 2 s . c o m return new String(Base64.encodeBase64(bytes), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new NestableRuntimeException(e); } }
From source file:net.nicholaswilliams.java.licensing.encryption.Hasher.java
/** * Calculate the SHA-512 message digest hash of the * provided string and return it with its binary * data Base64 encoded.//from www . j a v a 2s . c o m * * @param string The string to hash * @return the hashed string Base64 encoded. */ public static String hash(String string) { try { return new String( Base64.encodeBase64(MessageDigest.getInstance(Hasher.algorithm) .digest((string + Hasher.salt).getBytes(LicensingCharsets.UTF_8))), LicensingCharsets.UTF_8); } catch (NoSuchAlgorithmException e) { throw new AlgorithmNotSupportedException(Hasher.algorithm, e); } }
From source file:br.com.bluesoft.pronto.service.Seguranca.java
public static String encrypt(final String x) { try {//from w w w . j a v a2 s. c om final MessageDigest md = MessageDigest.getInstance("MD5"); md.update(x.getBytes()); final byte[] hashMd5 = md.digest(); final byte[] base64 = Base64.encodeBase64(hashMd5); return new String(base64); } catch (final Exception e) { return null; } }