List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:net.sf.hajdbc.codec.crypto.CipherCodec.java
/** * {@inheritDoc}//from w w w . j a v a 2s. c o m * @see net.sf.hajdbc.codec.Codec#encode(java.lang.String) */ @Override public String encode(String value) throws SQLException { try { Cipher cipher = Cipher.getInstance(this.key.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, this.key); return new String(Base64.encodeBase64(cipher.doFinal(value.getBytes()))); } catch (GeneralSecurityException e) { throw new SQLException(e); } }
From source file:info.fcrp.keepitsafe.util.Crypt.java
public synchronized static String crypt(String plain) { init();/* w ww.j a va 2s. co m*/ try { cryptCipher.update(plain.getBytes()); byte[] crypted = cryptCipher.doFinal(); byte[] crypted64 = Base64.encodeBase64(crypted); String cryptedString = new String(crypted64); return cryptedString; } catch (IllegalBlockSizeException e) { throw new RuntimeException(e); } catch (BadPaddingException e) { throw new RuntimeException(e); } }
From source file:io.apiman.common.auth.AuthTokenUtil.java
/** * Produce a token suitable for transmission. This will generate the auth token, * then serialize it to a JSON string, then Base64 encode the JSON. * @param principal//w ww . j a va 2s .c om * @param roles * @param expiresInMillis */ public static final String produceToken(String principal, Set<String> roles, int expiresInMillis) { AuthToken authToken = createAuthToken(principal, roles, expiresInMillis); String json = toJSON(authToken); return StringUtils.newStringUtf8(Base64.encodeBase64(StringUtils.getBytesUtf8(json))); }
From source file:com.example.austin.test.TextActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text); Thread thread = new Thread(new Runnable() { @Override// ww w . j a v a 2s. c o m public void run() { try { Bundle bundle = getIntent().getExtras(); Bitmap photo = (Bitmap) bundle.get("photo"); ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.PNG, 100, stream1); byte[] fileContent = stream1.toByteArray(); String license_code = "59D1D7B4-61FD-49EB-A549-C77E08B7103A"; String user_name = "austincheng16"; String ocrURL = "http://www.ocrwebservice.com/restservices/processDocument?gettext=true"; URL url = new URL(ocrURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64((user_name + ":" + license_code).getBytes()))); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Content-Length", Integer.toString(fileContent.length)); try { OutputStream stream = connection.getOutputStream(); stream.write(fileContent); stream.close(); int httpCode = connection.getResponseCode(); if (httpCode == HttpURLConnection.HTTP_OK) { String jsonResponse = GetResponseToString(connection.getInputStream()); PrintOCRResponse(jsonResponse); } else { String jsonResponse = GetResponseToString(connection.getErrorStream()); JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(jsonResponse); Log.i("austin", "Error Message: " + jsonObj.get("ErrorMessage")); } connection.disconnect(); } catch (IOException e) { Log.i("austin", "IOException"); } } catch (Exception e) { e.printStackTrace(); } } }); thread.start(); }
From source file:com.hortonworks.amstore.view.proxy.Proxy.java
private HashMap<String, String> makeHeaders() { HashMap<String, String> headers = new HashMap<String, String>(); headers.putAll(customHeaders);/*from ww w . j a va 2 s . c o m*/ if (isUseAuthorization()) { String authString = username + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); headers.put("Authorization", "Basic " + authStringEnc); } return headers; }
From source file:com.liferay.mobile.sdk.util.PortraitUtil.java
protected static void appendToken(StringBuilder sb, String uuid) throws Exception { if (Validator.isNull(uuid)) { return;//from w ww .j a v a 2 s.c o m } MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(uuid.getBytes()); byte[] bytes = digest.digest(); byte[] encodedBytes = Base64.encodeBase64(bytes); String token = new String(encodedBytes); sb.append("&img_id_token="); sb.append(URLEncoder.encode(token, "UTF8")); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java
/** * * @param hex/* w w w . ja v a 2s .co m*/ * @return * @throws DecoderException */ public String hexToBase64(String hex) throws DecoderException { String b64data = new String(Base64.encodeBase64(Hex.decodeHex(hex.toCharArray()))); return b64data; }
From source file:com.cloudera.flume.core.DigestDecorator.java
@Override public synchronized void append(Event e) throws IOException, InterruptedException { this.stomach.reset(); this.stomach.update(e.getBody()); byte digest[] = this.stomach.digest(); if (this.encodeBase64) { digest = Base64.encodeBase64(digest); }//from w w w . j a va2 s .c o m e.set(this.attr, digest); super.append(e); }
From source file:dtu.ds.warnme.utils.SecurityUtils.java
public static String hashMD5Base64(String stringToHash) throws UnsupportedEncodingException { byte[] bytes = stringToHash.getBytes(CHARSET_UTF8); byte[] md5bytes = DigestUtils.md5(bytes); byte[] base64bytes = Base64.encodeBase64(md5bytes); return new String(base64bytes, CHARSET_UTF8); }
From source file:cn.ucloud.sdk.utils.EncoderUtils.java
/** * Base64/*from w w w.j a v a 2 s . c o m*/ * @param str * @return */ public static String base64(String str) { String result = null; try { result = new String(Base64.encodeBase64(str.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { LogUtils.exception(logger, e); } return result; }