List of usage examples for android.util Base64 encodeToString
public static String encodeToString(byte[] input, int flags)
From source file:com.example.android.apis.graphics.FingerPaint.java
private void saveBitmap(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos); byte[] b = baos.toByteArray(); String encodedImage = Base64.encodeToString(b, Base64.DEFAULT); SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this); Editor edit = shre.edit();//from www . jav a 2s . c om edit.putString("paint_image_data", encodedImage); edit.commit(); }
From source file:com.mimo.service.api.MimoOauth2Client.java
/** * This function calls the Mimo Server along with the client info and server * authenticates the client and returns a valid access_token * /* w w w .j a v a2 s. c om*/ * @param p_code * : code received from the Mimo Server * * @return <b>m_token</b> : is the access token returned from the server **/ private String requesttoken(String p_code) { String m_loadUrl = m_api.requesttoken(p_code); DefaultHttpClient m_httpClient = new DefaultHttpClient(); HttpPost m_post = new HttpPost(m_loadUrl); // String m_authString = "mimo:mimo"; String m_authString = MimoAPIConstants.USERNAME + ":" + MimoAPIConstants.PASSWORD; String m_authStringEnc = Base64.encodeToString(m_authString.getBytes(), Base64.NO_WRAP); m_post.addHeader(MimoAPIConstants.HEADER_TEXT_AUTHORIZATION, MimoAPIConstants.HEADER_TEXT_BASIC + m_authStringEnc); HttpResponse m_response = null; String m_token = null; try { m_response = m_httpClient.execute(m_post); JSONObject m_jsonResp; try { m_jsonResp = new JSONObject(convertStreamToString(m_response.getEntity().getContent())); // m_token = m_jsonResp.getString("access_token"); m_token = m_jsonResp.getString(MimoAPIConstants.GET_ACCESS_TOKEN); if (MimoAPIConstants.DEBUG) { Log.d(TAG + "Access Token", m_token); } return m_token; } catch (IllegalStateException p_e) { if (MimoAPIConstants.DEBUG) { Log.e(TAG, p_e.getMessage()); } } catch (JSONException p_e) { if (MimoAPIConstants.DEBUG) { Log.e(TAG, p_e.getMessage()); } } } catch (ClientProtocolException p_e) { if (MimoAPIConstants.DEBUG) { Log.e(TAG, p_e.getMessage()); } } catch (IOException p_e) { if (MimoAPIConstants.DEBUG) { Log.e(TAG, p_e.getMessage()); } } return ""; }
From source file:com.adeven.adjustio.PackageBuilder.java
private void addMap(Map<String, String> parameters, String key, Map<String, String> map) { if (null == map) { return;//from w ww .j a v a2 s . c o m } JSONObject jsonObject = new JSONObject(map); byte[] jsonBytes = jsonObject.toString().getBytes(); String encodedMap = Base64.encodeToString(jsonBytes, Base64.NO_WRAP); addString(parameters, key, encodedMap); }
From source file:com.etalio.android.EtalioExtendedAPI.java
private boolean privateSignIn(byte[] body) throws IOException, EtalioHttpException, EtalioTokenException { Log.v(SDK_TAG, "privateSignIn"); Map<String, String> headers = new HashMap<String, String>(); addEtalioUserAgent(headers);/*ww w . j a v a 2 s .c o m*/ String authenticationString = mClientId + ":" + mClientSecret; String authenticationString64 = Base64.encodeToString(authenticationString.getBytes(), Base64.NO_WRAP); headers.put("Authorization", "Basic " + authenticationString64); Log.v(TAG, "privateSignIn:: POST " + authenticationString + " " + getUrl("token", null) + " " + new String(body, "UTF-8")); HttpRequest request = new HttpRequest(HttpRequest.HttpMethod.POST, getUrl("token", null), headers, body, CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED, body.length); HttpResponse<TokenResponse> response = null; response = getHttpClient().executeRequest(request, new GsonHttpBodyConverter<TokenResponse>(), TokenResponse.class); Log.v(TAG, "privateSignIn::" + response.getStatus() + " : " + new String(getHttpBodyConverter().toBody(response.getBody(), "UTF-8"), "UTF-8")); updateEtalioToken(response); return true; }
From source file:com.murrayc.galaxyzoo.app.provider.client.ZooniverseClient.java
private String generateAuthorizationHeader(final String authName, final String authApiKey) { //See the similar code in Zooniverse's user.coffee source code: //https://github.com/zooniverse/Zooniverse/blob/master/src/models/user.coffee#L49 final String str = authName + ":" + authApiKey; byte[] asBytes = null; try {/*from w w w. j ava2s . c om*/ asBytes = str.getBytes(Utils.STRING_ENCODING); } catch (final UnsupportedEncodingException e) { //This is incredibly unlikely for the UTF-8 encoding, //so we just log it instead of trying to recover from it. Log.error("generateAuthorizationHeader(): String.getBytes() failed", e); return null; } return "Basic " + Base64.encodeToString(asBytes, Base64.DEFAULT); }
From source file:com.evothings.BLE.java
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { if (mScanCallbackContext == null) { return;//from ww w . jav a2 s. co m } try { //System.out.println("onLeScan "+device.getAddress()+" "+rssi+" "+device.getName()); JSONObject o = new JSONObject(); o.put("address", device.getAddress()); o.put("rssi", rssi); o.put("name", device.getName()); o.put("scanRecord", Base64.encodeToString(scanRecord, Base64.NO_WRAP)); keepCallback(mScanCallbackContext, o); } catch (JSONException e) { mScanCallbackContext.error(e.toString()); } }
From source file:com.leanplum.internal.WebSocketClient.java
private String createSecret() { byte[] nonce = new byte[16]; for (int i = 0; i < 16; i++) { nonce[i] = (byte) (Math.random() * 256); }/*from ww w .j a v a 2s .c o m*/ return Base64.encodeToString(nonce, Base64.DEFAULT).trim(); }
From source file:com.example.android.fingerprintdialog.MainActivity.java
private void showConfirmation(byte[] encrypted) { findViewById(R.id.confirmation_message).setVisibility(View.VISIBLE); if (encrypted != null) { TextView v = (TextView) findViewById(R.id.encrypted_message); v.setVisibility(View.VISIBLE); v.setText(Base64.encodeToString(encrypted, 0 /* flags */)); }//from w ww .j a v a 2 s. c o m }
From source file:com.codebutler.farebot.card.felica.FelicaCard.java
@Override public Element toXML() throws Exception { Element root = super.toXML(); Document doc = root.getOwnerDocument(); Element idmElement = doc.createElement("idm"); idmElement.setTextContent(Base64.encodeToString(mIDm.getBytes(), Base64.DEFAULT)); root.appendChild(idmElement);/*from w w w .ja v a2 s.c o m*/ Element pmmElement = doc.createElement("pmm"); pmmElement.setTextContent(Base64.encodeToString(mPMm.getBytes(), Base64.DEFAULT)); root.appendChild(pmmElement); Element systemsElement = doc.createElement("systems"); for (FelicaSystem system : mSystems) { Element systemElement = doc.createElement("system"); systemElement.setAttribute("code", String.valueOf(system.getCode())); Element servicesElement = doc.createElement("services"); for (FelicaService service : system.getServices()) { Element serviceElement = doc.createElement("service"); serviceElement.setAttribute("code", String.valueOf(service.getServiceCode())); Element blocksElement = doc.createElement("blocks"); for (FelicaBlock block : service.getBlocks()) { Element blockElement = doc.createElement("block"); blockElement.setAttribute("address", String.valueOf(block.getAddress())); blockElement.setTextContent(Base64.encodeToString(block.getData(), Base64.DEFAULT)); blocksElement.appendChild(blockElement); } serviceElement.appendChild(blocksElement); servicesElement.appendChild(serviceElement); } systemElement.appendChild(servicesElement); systemsElement.appendChild(systemElement); } root.appendChild(systemsElement); return root; }
From source file:com.owncloud.android.utils.EncryptionUtils.java
public static String encodeBytesToBase64String(byte[] bytes) { return Base64.encodeToString(bytes, Base64.NO_WRAP); }