List of usage examples for android.util Base64 NO_WRAP
int NO_WRAP
To view the source code for android.util Base64 NO_WRAP.
Click Source Link
From source file:com.hybris.mobile.lib.commerce.service.OCCServiceHelper.java
@Override public boolean authenticate(final ResponseReceiverEmpty responseReceiver, final String requestId, final QueryLogin queryLogin, final boolean shouldUseCache, final List<View> viewsToDisable, final OnRequestListener onRequestListener) { if (queryLogin == null || StringUtils.isBlank(queryLogin.getUsername())) { throw new IllegalArgumentException("The username parameter is missing from the query"); }//from ww w.j a v a 2 s .c o m Map<String, Object> parameters = buildLoginParameters(queryLogin, Constants.Login.CLIENT_ID, Constants.Login.GRANT_TYPE_LOGIN); // Constructing the headers map Map<String, String> headers = new HashMap<>(); String authValue = "Basic " + Base64.encodeToString(Constants.Login.AUTHORIZATION.getBytes(), Base64.NO_WRAP); headers.put(Constants.Login.PARAM_HEADER_AUTHORIZATION, authValue); // We want to save the user information before sending back the result ResponseReceiver<UserInformation> responseReceiverBeforeCallback = new ResponseReceiver<UserInformation>() { @Override public void onResponse(Response<UserInformation> response) { // Saving the user information for future authorized requests saveUserInformation(response.getData(), queryLogin.getUsername()); responseReceiver.onResponse(Response.createResponse(new EmptyResponse(), requestId, true)); } @Override public void onError(Response<ErrorList> response) { responseReceiver.onError(response); } }; return execute(responseReceiverBeforeCallback, DataConverter.Helper.build(UserInformation.class, ErrorList.class, null), shouldUseCache, requestId, UrlHelper.getWebserviceTokenUrl(mContext, mConfiguration), parameters, headers, false, HttpUtils.HTTP_METHOD_POST, viewsToDisable, onRequestListener); }
From source file:com.mobile.natal.natalchart.NetworkUtilities.java
private static String getB64Auth(String login, String pass) { String source = login + ":" + pass; String ret = "Basic " + Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP); return ret;//w ww .j a v a 2 s . com }
From source file:im.delight.android.webrequest.WebRequest.java
protected String getAuthDigest() { if (mUsername != null && mPassword != null) { return "Basic " + Base64.encodeToString((mUsername + ":" + mPassword).getBytes(), Base64.NO_WRAP); } else {/*from w w w . ja va 2 s.c om*/ return ""; } }
From source file:com.android.mms.service.http.NetworkAwareHttpClient.java
/** * Generates a cURL command equivalent to the given request. *///ww w . j a va 2 s . c om private static String toCurl(HttpUriRequest request, boolean logAuthToken) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("curl "); // add in the method builder.append("-X "); builder.append(request.getMethod()); builder.append(" "); for (Header header : request.getAllHeaders()) { if (!logAuthToken && (header.getName().equals("Authorization") || header.getName().equals("Cookie"))) { continue; } builder.append("--header \""); builder.append(header.toString().trim()); builder.append("\" "); } URI uri = request.getURI(); // If this is a wrapped request, use the URI from the original // request instead. getURI() on the wrapper seems to return a // relative URI. We want an absolute URI. if (request instanceof RequestWrapper) { HttpRequest original = ((RequestWrapper) request).getOriginal(); if (original instanceof HttpUriRequest) { uri = ((HttpUriRequest) original).getURI(); } } builder.append("\""); builder.append(uri); builder.append("\""); if (request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request; HttpEntity entity = entityRequest.getEntity(); if (entity != null && entity.isRepeatable()) { if (entity.getContentLength() < 1024) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); entity.writeTo(stream); if (isBinaryContent(request)) { String base64 = Base64.encodeToString(stream.toByteArray(), Base64.NO_WRAP); builder.insert(0, "echo '" + base64 + "' | base64 -d > /tmp/$$.bin; "); builder.append(" --data-binary @/tmp/$$.bin"); } else { String entityString = stream.toString(); builder.append(" --data-ascii \"").append(entityString).append("\""); } } else { builder.append(" [TOO MUCH DATA TO INCLUDE]"); } } } return builder.toString(); }
From source file:nl.hnogames.domoticzapi.Utils.RequestUtil.java
/** * Method to create a basic HTTP base64 encrypted authentication header * * @param username Username//from w w w . j av a 2s.c o m * @param password Password * @return Base64 encrypted header map */ public static Map<String, String> createBasicAuthHeader(String username, String password, Map<String, String> headerMap) { if (headerMap == null) headerMap = new HashMap<>(); String credentials = username + ":" + password; String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); headerMap.put("Authorization", "Basic " + base64EncodedCredentials); return headerMap; }
From source file:com.ledger.android.u2f.bridge.MainActivity.java
private String createU2FResponseSign(U2FContext context, byte[] signature) { try {/* www. jav a2s . c o m*/ JSONObject response = new JSONObject(); response.put(TAG_JSON_TYPE, SIGN_RESPONSE_TYPE); response.put(TAG_JSON_REQUESTID, context.getRequestId()); JSONObject responseData = new JSONObject(); responseData.put(TAG_JSON_KEYHANDLE, Base64.encodeToString(context.getChosenKeyHandle(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); responseData.put(TAG_JSON_SIGNATUREDATA, Base64.encodeToString(signature, 0, signature.length - 2, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); String clientData = createClientData(context); responseData.put(TAG_JSON_CLIENTDATA, Base64.encodeToString(clientData.getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); response.put(TAG_JSON_RESPONSEDATA, responseData); return response.toString(); } catch (Exception e) { Log.e(TAG, "Error encoding request"); return null; } }
From source file:org.quantumbadger.redreader.reddit.api.RedditOAuth.java
public static FetchAccessTokenResult fetchAccessTokenSynchronous(final Context context, final RefreshToken refreshToken) { final String uri = ACCESS_TOKEN_URL; StatusLine responseStatus = null;//from w w w. ja v a2 s. c o m try { final HttpClient httpClient = CacheManager.createHttpClient(context); final HttpPost request = new HttpPost(uri); final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token")); nameValuePairs.add(new BasicNameValuePair("refresh_token", refreshToken.token)); request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); request.addHeader("Authorization", "Basic " + Base64.encodeToString((CLIENT_ID + ":").getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); final HttpResponse response = httpClient.execute(request); responseStatus = response.getStatusLine(); if (responseStatus.getStatusCode() != 200) { return new FetchAccessTokenResult(FetchAccessTokenResultStatus.UNKNOWN_ERROR, new RRError(context.getString(R.string.error_unknown_title), context.getString(R.string.message_cannotlogin), null, responseStatus, request.getURI().toString())); } final JsonValue jsonValue = new JsonValue(response.getEntity().getContent()); jsonValue.buildInThisThread(); final JsonBufferedObject responseObject = jsonValue.asObject(); final String accessTokenString = responseObject.getString("access_token"); if (accessTokenString == null) { throw new RuntimeException("Null access token: " + responseObject.getString("error")); } final AccessToken accessToken = new AccessToken(accessTokenString); return new FetchAccessTokenResult(accessToken); } catch (IOException e) { return new FetchAccessTokenResult(FetchAccessTokenResultStatus.CONNECTION_ERROR, new RRError(context.getString(R.string.error_connection_title), context.getString(R.string.error_connection_message), e, responseStatus, uri)); } catch (Throwable t) { return new FetchAccessTokenResult(FetchAccessTokenResultStatus.UNKNOWN_ERROR, new RRError(context.getString(R.string.error_unknown_title), context.getString(R.string.error_unknown_message), t, responseStatus, uri)); } }
From source file:org.ttrssreader.net.JSONConnector.java
/** * Tries to login to the ttrss-server with the base64-encoded password. * * @return true on success, false otherwise *///w w w .j a v a2 s . co m private boolean login() { long time = System.currentTimeMillis(); // Just login once, check if already logged in after acquiring the lock on mSessionId if (sessionId != null && !lastError.equals(NOT_LOGGED_IN)) return true; synchronized (lock) { try { if (sessionId != null && !lastError.equals(NOT_LOGGED_IN)) return true; // Login done while we were waiting for the lock Map<String, String> params = new HashMap<>(); params.put(PARAM_OP, VALUE_LOGIN); params.put(PARAM_USER, Controller.getInstance().username()); params.put(PARAM_PW, Base64.encodeToString(Controller.getInstance().password().getBytes("UTF-8"), Base64.NO_WRAP)); try { sessionId = readResult(params, true, false); if (sessionId != null) { Log.d(TAG, "login: " + (System.currentTimeMillis() - time) + "ms"); return true; } } catch (IOException e) { if (!hasLastError) { hasLastError = true; lastError = formatException(e); } } if (!hasLastError) { // Login didnt succeed, write message hasLastError = true; lastError = MyApplication.context().getString(R.string.Error_NotLoggedIn); } } catch (UnsupportedEncodingException e) { hasLastError = true; lastError = MyApplication.context().getString(R.string.Error_EncodePassword); } return false; } }
From source file:com.hkm.oc.wv.supportwebview.webviewSupports.java
protected void SavePNG(final int requestCode, final Uri filepath_uri) { final AsyncTask<Integer, Void, Boolean> task = new AsyncTask<Integer, Void, Boolean>() { private String error = ""; // private String imageEncoded = ""; @Override//from w w w .j a va 2 s. c om protected Boolean doInBackground(Integer... k) { boolean result = false; try { Bitmap immagex = null; if (requestCode == WLR_CLIENT_SIGN) current_job_task.saveSignWLRClient(filepath_uri); if (requestCode == WLR_TEAM_SIGN) current_job_task.saveSignWLRTeam(filepath_uri); if (requestCode == WCS_CLIENT_SIGN) current_job_task.saveSignWCSClient(filepath_uri); // immagex = BitmapFactory.decodeStream(mFragmentActivity.getContentResolver().openInputStream(filepath_uri)); immagex = Tool.LoadScaledBitmap(mFragmentActivity.getContentResolver(), filepath_uri, 100000); if (immagex == null) throw new FileNotFoundException(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); //http://stackoverflow.com/questions/22031636/convert-android-base64-bitmap-and-display-on-html-base64-image final String imageEncoded = Base64.encodeToString(b, Base64.NO_WRAP); // final int strFileName = k[0]; // mWebView.loadUrl("javascript:PControl.checkComplete()"); /* final String m = new String(imageEncoded); final StringBuffer strBuilder = new StringBuffer(); final int bufferchars = 200; final int t = (int) Math.ceil(m.length() / bufferchars); for (int i = 0; i < t; i++) { final StringBuilder cc = new StringBuilder(); int next = (i + 1) * bufferchars; int dest = next > m.length() ? m.length() : next; final CharSequence g = m.subSequence(i * bufferchars, dest); cc.append(g); strBuilder.append(g); mWebView.loadUrl("javascript:PControl.fillPNG('" + cc.toString() + "');"); } String TAG = "loading image tag"; Log.d(TAG, strBuilder.toString());*/ result = true; } catch (FileNotFoundException e) { result = false; } catch (Exception e) { result = false; } return result; } @Override protected void onPostExecute(Boolean saved) { runOnUiThread(new Runnable() { @Override public void run() { progressBar_dismiss("signature saved and confirmed.", new DsingleCB() { @Override public void oncontified(DialogFragment dialog) { if (requestCode == WLR_CLIENT_SIGN) mWebView.loadUrl( "javascript:PControl.fillEndF(1,'" + filepath_uri.toString() + "');"); if (requestCode == WLR_TEAM_SIGN) mWebView.loadUrl( "javascript:PControl.fillEndF(2,'" + filepath_uri.toString() + "');"); if (requestCode == WCS_CLIENT_SIGN) mWebView.loadUrl( "javascript:PControl.fillEndF(3,'" + filepath_uri.toString() + "');"); } }); } }); } }; task.execute(requestCode); }
From source file:com.mpower.daktar.android.utilities.WebUtils.java
public static String getSHA512(final String input) { String retval = ""; try {/*from w ww .j av a 2s .co m*/ final MessageDigest m = MessageDigest.getInstance("SHA-512"); final byte[] out = m.digest(input.getBytes()); retval = Base64.encodeToString(out, Base64.NO_WRAP); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return retval; }