List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.tecapro.inventory.common.util.CommonUtil.java
/** * encodeBase64 object//from w ww.ja v a 2s . co m * * @param obj * @return * @throws Exception */ public byte[] serialize(Object obj) throws Exception { ByteArrayOutputStream byteStream = null; ObjectOutputStream ostream = null; byte[] result = null; try { byteStream = new ByteArrayOutputStream(); ostream = new ObjectOutputStream(new BufferedOutputStream(byteStream)); ostream.writeObject(obj); ostream.flush(); result = Base64.encodeBase64(byteStream.toByteArray()); } finally { if (byteStream != null) { byteStream.close(); } if (ostream != null) { ostream.close(); } } return result; }
From source file:dtu.ds.warnme.utils.SecurityUtils.java
public static String hashSHA512Base64(String stringToHash) throws UnsupportedEncodingException { byte[] bytes = stringToHash.getBytes(CHARSET_UTF8); byte[] sha512bytes = DigestUtils.sha512(bytes); byte[] base64bytes = Base64.encodeBase64(sha512bytes); return new String(base64bytes, CHARSET_UTF8); }
From source file:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java
private static String getEncodedCreds(String user, String password) { String plainCreds = String.format("%s:%s", user, password); byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); return new String(base64CredsBytes); }
From source file:com.threewks.thundr.util.Encoder.java
public Encoder base64() { data = Base64.encodeBase64(data); return this; }
From source file:com.seer.datacruncher.utils.CryptoUtil.java
/** * Method To Encrypt The Given String//from w ww .j a va2 s.c o m */ public String encrypt(String unencryptedString) { String encryptedString = null; try { cipher.init(Cipher.ENCRYPT_MODE, key); if (!checkKeyVerify()) unencryptedString = unencryptedString.substring(0, unencryptedString.length() / 2); byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT); byte[] encryptedText = cipher.doFinal(plainText); encryptedString = new String(Base64.encodeBase64(encryptedText)); } catch (Exception e) { e.printStackTrace(); } return encryptedString; }
From source file:com.amediamanager.util.S3FormSigner.java
/** * The SignRequest method takes a set of AWS credentials and the S3 upload policy string and returns the encoded policy and the signature. * * @param creds the AWS credentials to be used for signing the request * @param policy the policy file to applied to the upload * @return an array of strings containing the base 64 encoded policy (index 0) and the signature (index 1). *///from w w w . j a va2 s . com String[] signRequest(AWSCredentialsProvider credsProvider, String policy) { String[] policyAndSignature = new String[2]; try { // Create a Base64 encoded version of the policy string for placement in the form and // for use in signature generation. Returns are stripped out from the policy string. String encodedPolicy = new String( Base64.encodeBase64(policy.replaceAll("\n", "").replaceAll("\r", "").getBytes("UTF-8"))); // AWS signatures are generated using SHA1 HMAC signing. Mac hmac = Mac.getInstance("HmacSHA1"); // Generate the signature using the Secret Key from the AWS credentials hmac.init(new SecretKeySpec(credsProvider.getCredentials().getAWSSecretKey().getBytes("UTF-8"), "HmacSHA1")); String signature = new String(Base64.encodeBase64(hmac.doFinal(encodedPolicy.getBytes("UTF-8")))); // Pack the encoded policy and the signature into a string array policyAndSignature[0] = encodedPolicy; policyAndSignature[1] = signature; } catch (UnsupportedEncodingException e) { LOG.error("Unsupport encoding", e); } catch (NoSuchAlgorithmException e) { LOG.error("No such algorithm", e); } catch (InvalidKeyException e) { LOG.error("Invalid key", e); } return policyAndSignature; }
From source file:com.appdynamics.openstack.nova.CreateServerOptions.java
public void setFile(byte[] file, String filePath) { this.file = Base64.encodeBase64(file); this.filePath = filePath; }
From source file:gaffer.accumulo.utils.IngestUtils.java
/** * Given some split points, write a Base64 encoded splits file. * // w w w .j av a 2 s . co m * @param splits The split points * @param fs The FileSystem in which to create the splits file * @param splitsFile The location of the output splits file * @throws IOException */ public static void writeSplitsFile(Collection<Text> splits, FileSystem fs, Path splitsFile) throws IOException { PrintStream out = null; try { out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true))); for (Text split : splits) { out.println(new String(Base64.encodeBase64(split.getBytes()))); } } finally { IOUtils.closeStream(out); } }
From source file:com.thinkbiganalytics.policy.standardization.Base64Encode.java
@Override public Object convertRawValue(Object value) { try {//from ww w. jav a 2s . c o m byte[] val = null; if (value instanceof byte[]) { val = (byte[]) value; } else { val = ((String) value).getBytes("UTF-8"); } if (Base64Output.BINARY.equals(base64Output)) { byte[] encoded = Base64.encodeBase64(val); return encoded; } else if (Base64Output.STRING.equals(base64Output)) { return Base64.encodeBase64URLSafeString(val); } } catch (UnsupportedEncodingException e) { return null; } return null; }
From source file:com.fortmoon.utils.SymmetricCypher.java
public String encypher(String data) { byte cleartext[] = data.getBytes(); try {//www . j ava 2 s . c o m Cipher jceCipher = Cipher.getInstance(cipherTransformation); jceCipher.init(1, secretKeySpec); byte ciphertext[] = jceCipher.doFinal(cleartext); byte encodedText[] = Base64.encodeBase64(ciphertext); return new String(encodedText); } catch (GeneralSecurityException gse) { throw new EncryptionRuntimeException("Failed to encrypt", gse); } }