List of usage examples for android.util Base64 URL_SAFE
int URL_SAFE
To view the source code for android.util Base64 URL_SAFE.
Click Source Link
From source file:com.skubit.android.billing.BillingServiceBinder.java
public static String hash(byte[] message) { int flag = Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE; try {/*from www. j av a 2 s .com*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(message); return Base64.encodeToString(md.digest(), flag); } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) { } return null; }
From source file:Main.java
public static String largeFileSha1(File file) { InputStream inputStream = null; try {/*from ww w . jav a2 s . c o m*/ MessageDigest gsha1 = MessageDigest.getInstance("SHA1"); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); inputStream = new BufferedInputStream(new FileInputStream(file)); byte[] buffer = new byte[1024]; int nRead = 0; int block = 0; int count = 0; final int BLOCK_SIZE = 4 * 1024 * 1024; while ((nRead = inputStream.read(buffer)) != -1) { count += nRead; sha1.update(buffer, 0, nRead); if (BLOCK_SIZE == count) { gsha1.update(sha1.digest()); sha1 = MessageDigest.getInstance("SHA1"); block++; count = 0; } } if (count != 0) { gsha1.update(sha1.digest()); block++; } byte[] digest = gsha1.digest(); byte[] blockBytes = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(block).array(); byte[] result = ByteBuffer.allocate(4 + digest.length).put(blockBytes, 0, blockBytes.length) .put(digest, 0, digest.length).array(); return Base64.encodeToString(result, Base64.URL_SAFE | Base64.NO_WRAP); } catch (Exception e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
From source file:com.auth0.util.Telemetry.java
public String asBase64() { Map<String, Object> info = new HashMap<>(); info.put("name", getName("Lock.Android")); info.put("version", getVersion(BuildConfig.VERSION_NAME)); if (isNonEmpty(this.libraryVersion)) { info.put("lib_version", this.libraryVersion); }//from www . j a v a2 s . c om if (this.extra != null) { info.putAll(this.extra); } String clientInfo = null; try { String json = new ObjectMapper().writeValueAsString(info); Log.v(TAG, "Telemetry JSON is " + json); clientInfo = Base64.encodeToString(json.getBytes(Charset.defaultCharset()), Base64.URL_SAFE | Base64.NO_WRAP); } catch (JsonProcessingException e) { Log.w(TAG, "Failed to build client info", e); } return clientInfo; }
From source file:com.ferjuarez.androidthingsdemo.PhotoEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, PhotoEntry model, int position) { // Display the timestamp if (model != null && model.getTimestamp() != null) { CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getThumbnail() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getThumbnail(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else { Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.mipmap.ic_launcher); viewHolder.image.setImageDrawable(placeholder); }// ww w . j a va2s .co m } } // Display the metadata /*if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); }*/ }
From source file:com.example.androidthings.doorbell.DoorbellEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, DoorbellEntry model, int position) { // Display the timestamp CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getImage() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getImage(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else {/*from w w w. j a v a2s. c om*/ Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.drawable.ic_image); viewHolder.image.setImageDrawable(placeholder); } } // Display the metadata if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); } }
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 ww .j a v a 2s. 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:com.distimo.sdk.Utils.java
@SuppressLint({ "NewApi", "InlinedApi" }) static String base64Encode(byte[] data) { String result = null;// w w w. j a va2s.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:org.ebayopensource.fidouafclient.op.Auth.java
private String getFinalChalenge(AuthenticationRequest request) { FinalChallengeParams fcParams = new FinalChallengeParams(); fcParams.appID = request.header.appID; Preferences.setSettingsParam("appID", fcParams.appID); fcParams.facetID = getFacetId();/*from www. j a v a 2 s. c o m*/ fcParams.challenge = request.challenge; return Base64.encodeToString(gson.toJson(fcParams).getBytes(), Base64.URL_SAFE); }
From source file:com.achep.base.billing.CheckoutInternal.java
/** * Method deciphers previously ciphered message * * @param message ciphered message/*from www. j ava 2s .co m*/ * @param salt salt which was used for ciphering * @return deciphered message */ @NonNull private String fromX(@NonNull String message, @NonNull String salt) throws IllegalArgumentException { return x(new String(Base64.decode(message, Base64.URL_SAFE)), salt); }