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.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.certificate.DefaultJSONSigner.java
private String encodeUrlSafe(byte[] data) throws UnsupportedEncodingException { return new String(Base64.encode(data, Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8"); }
From source file:com.google.samples.apps.abelana.AbelanaThings.java
public AbelanaThings(Context ctx, String phint) { final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); final HttpTransport httpTransport = new NetHttpTransport(); Resources r = ctx.getResources(); byte[] android, server; byte[] password = new byte[32]; android = Base64.decode("vW7CmbQWdPjpdfpBU39URsjHQV50KEKoSfafHdQPSh8", Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP); server = Base64.decode(phint, Base64.URL_SAFE); int i = 0;/* w w w.ja va 2 s . c o m*/ for (byte b : android) { password[i] = (byte) (android[i] ^ server[i]); i++; } byte[] pw = Base64.encode(password, Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP); String pass = new String(pw); if (storage == null) { try { KeyStore keystore = KeyStore.getInstance("PKCS12"); keystore.load(r.openRawResource(R.raw.abelananew), pass.toCharArray()); credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory) .setServiceAccountId(r.getString(R.string.service_account)) .setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)) .setServiceAccountPrivateKey((PrivateKey) keystore.getKey("privatekey", pass.toCharArray())) .build(); storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(r.getString(R.string.app_name) + "/1.0").build(); } catch (CertificateException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("loaded"); } }
From source file:eu.codeplumbers.cosi.services.CosiFileDownloadService.java
@Override protected void onHandleIntent(Intent intent) { // Do the task here Log.i(CosiFileDownloadService.class.getName(), "Cosi Service running"); // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); Device device = Device.registeredDevice(); // cozy register device url fileUrl = device.getUrl() + "/ds-api/data/"; // concatenate username and password with colon for authentication final String credentials = device.getLogin() + ":" + device.getPassword(); authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); showNotification();/*from w w w .j a v a 2 s .co m*/ if (isNetworkAvailable()) { try { ArrayList<String> fileStrings = intent.getStringArrayListExtra("fileToDownload"); for (int i = 0; i < fileStrings.size(); i++) { File file = File.load(File.class, Long.valueOf(fileStrings.get(i))); String binaryRemoteId = file.getRemoteId(); if (!binaryRemoteId.isEmpty()) { mBuilder.setProgress(100, 0, false); mBuilder.setContentText("Downloading file: " + file.getName()); mNotifyManager.notify(notification_id, mBuilder.build()); URL urlO = null; try { urlO = new URL(fileUrl + binaryRemoteId + "/binaries/file"); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("GET"); conn.connect(); int lenghtOfFile = conn.getContentLength(); // read the response int status = conn.getResponseCode(); if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { EventBus.getDefault() .post(new FileSyncEvent(SERVICE_ERROR, conn.getResponseMessage())); stopSelf(); } else { int count = 0; InputStream in = new BufferedInputStream(conn.getInputStream(), 8192); java.io.File newFile = file.getLocalPath(); if (!newFile.exists()) { newFile.createNewFile(); } // Output stream to write file OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + java.io.File.separator + Constants.APP_DIRECTORY + java.io.File.separator + "files" + file.getPath() + "/" + file.getName()); byte data[] = new byte[1024]; long total = 0; while ((count = in.read(data)) != -1) { total += count; mBuilder.setProgress(lenghtOfFile, (int) total, false); mBuilder.setContentText("Downloading file: " + file.getName()); mNotifyManager.notify(notification_id, mBuilder.build()); // writing data to file output.write(data, 0, count); } // flushing output output.flush(); // closing streams output.close(); in.close(); file.setDownloaded(true); file.save(); } } catch (MalformedURLException e) { EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (ProtocolException e) { EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (IOException e) { EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } } } mNotifyManager.cancel(notification_id); EventBus.getDefault().post(new FileSyncEvent(REFRESH, "Sync OK")); } catch (Exception e) { e.printStackTrace(); mSyncRunning = false; EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); } } else { mSyncRunning = false; EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, "No Internet connection")); mBuilder.setContentText("Sync failed because no Internet connection was available"); mNotifyManager.notify(notification_id, mBuilder.build()); } }
From source file:org.openmidaas.app.common.Utils.java
public static String getAttributeDetailsLabel(AbstractAttribute<?> attribute) { String message = "Name: " + attribute.getName() + "\n" + "Value: " + attribute.toString() + "\n"; String[] jwsParams = null;/*from ww w. ja va 2s .c om*/ JSONObject object = null; String audience = ""; String issuer = ""; String subject = ""; if (attribute.getSignedToken() != null) { jwsParams = attribute.getSignedToken().split("\\."); try { object = new JSONObject(new String(Base64.decode(jwsParams[1], Base64.NO_WRAP), "UTF-8")); if (object != null) { if (object.getString("aud") != null) audience = object.getString("aud"); message += "Audience: " + audience + "\n"; if (object.getString("iss") != null) issuer = object.getString("iss"); message += "Issuer: " + issuer + "\n"; if (object.getString("sub") != null) subject = object.getString("sub"); message += "Subject: " + subject + "\n"; message += "Signature: " + jwsParams[2]; } } catch (Exception e) { } } return message; }
From source file:com.distimo.sdk.Utils.java
@SuppressLint({ "NewApi", "InlinedApi" }) static String base64Encode(byte[] data) { String result = null;//from w w w . ja va2 s . c om if (Build.VERSION.SDK_INT < 8) { //Build.VERSION.FROYO try { result = OldBase64.encodeBytes(data, OldBase64.URL_SAFE).replace("=", ""); } catch (final IOException ioe) { if (Utils.DEBUG) { ioe.printStackTrace(); } } } else { result = Base64.encodeToString(data, Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP); } return result; }
From source file:com.wms.opensource.shopfast.task.LoadProductsInCollectionTask.java
protected Void doInBackground(Integer... params) { // params[0] is the collection ID collectionID = params[0];/*from w w w . j av a 2s. c o m*/ /** Directly use HTTPClient to load products */ String urlString = "https://" + context.getString(R.string.ShopifyShopName) + ".myshopify.com/admin/products.json?collection_id=" + collectionID + "&page=" + page + "&limit=" + Constants.PRODUCTS_PER_PAGE; HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(urlString); try { String authentication = context.getString(R.string.ShopifyAPIKey) + ":" + context.getString(R.string.ShopifyPassword); byte[] byteArray = authentication.getBytes("UTF-8"); String base64 = Base64.encodeToString(byteArray, Base64.NO_WRAP); get.setHeader("Authorization", "Basic " + base64); get.setHeader("User-Agent", "Mozilla/5.0 ( compatible ) "); get.setHeader("Accept", "*/*"); HttpResponse resp = client.execute(get); if (resp.getStatusLine().getStatusCode() == 200) { HttpEntity entity = resp.getEntity(); if (entity != null) { String jsonString = EntityUtils.toString(entity); JSONObject productsObject = new JSONObject(jsonString); productsArrayString = productsObject.getString("products"); products = JSONProcessor.getProductsFromJSONArrayString(productsArrayString); } } else { errorString = "Error: " + resp.getStatusLine(); } } catch (ClientProtocolException e) { errorString = context.getString(R.string.retryOnError); } catch (IOException e) { errorString = context.getString(R.string.retryOnError); } catch (JSONException e) { errorString = context.getString(R.string.retryOnError); } return null; }
From source file:eu.codeplumbers.cosi.services.CosiNoteService.java
@Override protected void onHandleIntent(Intent intent) { // Do the task here Log.i(CosiNoteService.class.getName(), "Cosi Service running"); // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); Device device = Device.registeredDevice(); // delete all local notes new Delete().from(Note.class).execute(); // cozy register device url this.url = device.getUrl() + "/ds-api/request/note/cosiall/"; // concatenate username and password with colon for authentication final String credentials = device.getLogin() + ":" + device.getPassword(); authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); showNotification();/*from w ww . ja va 2s . c o m*/ if (isNetworkAvailable()) { try { URL urlO = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { String version = "0"; if (jsonArray.getJSONObject(i).has("version")) { version = jsonArray.getJSONObject(i).getString("version"); } JSONObject noteJson = jsonArray.getJSONObject(i).getJSONObject("value"); Note note = Note.getByRemoteId(noteJson.get("_id").toString()); if (note == null) { note = new Note(noteJson); } else { boolean versionIncremented = note.getVersion() < Integer .valueOf(noteJson.getString("version")); int modifiedOnServer = DateUtils.compareDateStrings( Long.valueOf(note.getLastModificationValueOf()), noteJson.getLong("lastModificationValueOf")); if (versionIncremented || modifiedOnServer == -1) { note.setTitle(noteJson.getString("title")); note.setContent(noteJson.getString("content")); note.setCreationDate(noteJson.getString("creationDate")); note.setLastModificationDate(noteJson.getString("lastModificationDate")); note.setLastModificationValueOf(noteJson.getString("lastModificationValueOf")); note.setParentId(noteJson.getString("parent_id")); // TODO: 10/3/16 // handle note paths note.setPath(noteJson.getString("path")); note.setVersion(Integer.valueOf(version)); } } mBuilder.setProgress(jsonArray.length(), i, false); mBuilder.setContentText("Getting note : " + note.getTitle()); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault() .post(new NoteSyncEvent(SYNC_MESSAGE, "Getting note : " + note.getTitle())); note.save(); } } else { EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, "Failed to parse API response")); } in.close(); conn.disconnect(); mNotifyManager.cancel(notification_id); EventBus.getDefault().post(new NoteSyncEvent(REFRESH, "Sync OK")); } catch (MalformedURLException e) { EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); mNotifyManager.notify(notification_id, mBuilder.build()); stopSelf(); } catch (ProtocolException e) { EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); mNotifyManager.notify(notification_id, mBuilder.build()); stopSelf(); } catch (IOException e) { EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); mNotifyManager.notify(notification_id, mBuilder.build()); stopSelf(); } catch (JSONException e) { EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); mNotifyManager.notify(notification_id, mBuilder.build()); stopSelf(); } } else { mSyncRunning = false; EventBus.getDefault().post(new NoteSyncEvent(SERVICE_ERROR, "No Internet connection")); mBuilder.setContentText("Sync failed because no Internet connection was available"); mNotifyManager.notify(notification_id, mBuilder.build()); } }
From source file:com.letsgood.synergykitsdkandroid.requestmethods.Delete.java
@Override public BufferedReader execute() { String uri = null;/*w w w .ja va2 s .c o m*/ //init check if (!Synergykit.isInit()) { SynergykitLog.print(Errors.MSG_SK_NOT_INITIALIZED); statusCode = Errors.SC_SK_NOT_INITIALIZED; return null; } //URI check uri = getUri().toString(); if (uri == null) { statusCode = Errors.SC_URI_NOT_VALID; return null; } //session token check if (sessionTokenRequired && sessionToken == null) { statusCode = Errors.SC_NO_SESSION_TOKEN; return null; } try { url = new URL(uri); // init url httpURLConnection = (HttpURLConnection) url.openConnection(); //open connection httpURLConnection.setConnectTimeout(CONNECT_TIMEOUT); //set connect timeout httpURLConnection.setReadTimeout(READ_TIMEOUT); //set read timeout httpURLConnection.setRequestMethod(REQUEST_METHOD); //set method httpURLConnection.addRequestProperty(PROPERTY_USER_AGENT, PROPERTY_USER_AGENT_VALUE); //set property httpURLConnection.addRequestProperty(PROPERTY_CONTENT_TYPE, ACCEPT_APPLICATION_VALUE); httpURLConnection.addRequestProperty(PROPERTY_AUTHORIZATION, "Basic " + Base64.encodeToString( (Synergykit.getTenant() + ":" + Synergykit.getApplicationKey()).getBytes(), Base64.NO_WRAP)); //set authorization if (Synergykit.getSessionToken() != null) httpURLConnection.addRequestProperty(PROPERTY_SESSION_TOKEN, Synergykit.getSessionToken()); statusCode = httpURLConnection.getResponseCode(); //get status code //read stream if (statusCode >= HttpURLConnection.HTTP_OK && statusCode < HttpURLConnection.HTTP_MULT_CHOICE) { return null; } else { return readStream(httpURLConnection.getErrorStream()); } } catch (Exception e) { statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE; e.printStackTrace(); return null; } }
From source file:eu.codeplumbers.cosi.services.CosiLoyaltyCardService.java
@Override protected void onHandleIntent(Intent intent) { // Do the task here Log.i(CosiLoyaltyCardService.class.getName(), "Cosi Service running"); // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); Device device = Device.registeredDevice(); // cozy register device url designUrl = device.getUrl() + "/ds-api/request/loyaltycard/all/"; syncUrl = device.getUrl() + "/ds-api/data/"; // concatenate username and password with colon for authentication final String credentials = device.getLogin() + ":" + device.getPassword(); authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); showNotification();/*from www. java2 s . c o m*/ if (isNetworkAvailable()) { try { EventBus.getDefault() .post(new LoyaltyCardSyncEvent(SYNC_MESSAGE, "Getting loyalty cards from Cozy...")); getRemoteLoyaltyCards(); mNotifyManager.cancel(notification_id); sendChangesToCozy(); EventBus.getDefault().post(new LoyaltyCardSyncEvent(REFRESH, "Sync OK")); } catch (Exception e) { e.printStackTrace(); mSyncRunning = false; EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); } } else { mSyncRunning = false; EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, "No Internet connection")); mBuilder.setContentText("Sync failed because no Internet connection was available"); mNotifyManager.notify(notification_id, mBuilder.build()); } }
From source file:com.danga.camli.UploadThread.java
private String getBasicAuthHeaderValue() { return "Basic " + Base64.encodeToString((USERNAME + ":" + mPassword).getBytes(), Base64.NO_WRAP); }