List of usage examples for android.util Base64 encodeToString
public static String encodeToString(byte[] input, int flags)
From source file:com.android.launcher3.Utilities.java
public static String encrypt(String input) { return Base64.encodeToString(input.getBytes(), Base64.CRLF); }
From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java
public String ubiGCPlayerDigestMessage(String message) { String resultSignature = ""; try {//from w ww .j a v a2 s . c om byte[] sha1Bytes = Utils.SHA1(message); //DebugLog.d(TAG, "ubiGCPlayerDigestMessage() sha1Str = " + sha1Str); //DebugLog.d(TAG, "ubiGCPlayerDigestMessage() sha1Bytes = " + Arrays.toString(sha1Bytes)); byte[] rsaEncryptedBytes = Utils.rsaEncrypt(Constants.sModulusStr, Constants.sPublicExponentStr, sha1Bytes); DebugLog.d(TAG, "ubiGCPlayerDigestMessage() rsaEncryptedBytes = " + Arrays.toString(rsaEncryptedBytes)); resultSignature = Base64.encodeToString(rsaEncryptedBytes, Base64.NO_WRAP); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block DebugLog.d(TAG, "excepion = " + e.getMessage()); return ""; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block DebugLog.d(TAG, "excepion = " + e.getMessage()); return ""; } return resultSignature; }
From source file:com.android.launcher3.Utilities.java
public static void saveBitmapPref(Activity activity, String packageName, Bitmap realImage) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); realImage.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); String encodedImage = Base64.encodeToString(b, Base64.DEFAULT); SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor edit = shre.edit(); edit.putString(packageName, encodedImage); edit.commit();//from w w w . j a v a2 s. c o m }
From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java
/** * client -> client//from w ww .j av a 2 s . c o m * BillingActivity * save all licenses in local HaspMap after do BillingActivity->checkInAppLicense() * @param sku * @param license */ public void notifyCheckLicenseResult(String sku, String license) { DebugLog.d(TAG, "0829 notifyCheckLicenseResult() sku= " + sku + ",license=" + license); String request; if (sku != null && license != null) { byte[] licenseBytes = license.getBytes(); String base64license = Base64.encodeToString(licenseBytes, Base64.DEFAULT); DebugLog.d(TAG, "0829 notifyCheckLicenseResult() sku= " + sku + ",base64license=" + base64license); mCheckLicenseMap.put(sku, base64license); } }
From source file:dev.ukanth.ufirewall.Api.java
/** * Encrypt the password/*from w w w .ja va 2s . c o m*/ * @param key * @param data * @return */ public static String hideCrypt(String key, String data) { if (key == null || data == null) return null; String encodeStr = null; try { DESKeySpec desKeySpec = new DESKeySpec(key.getBytes(charsetName)); SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm); SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec); byte[] dataBytes = data.getBytes(charsetName); Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, secretKey); encodeStr = Base64.encodeToString(cipher.doFinal(dataBytes), base64Mode); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage()); } return encodeStr; }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
/** * this method takes the date of today and the logged in user id and returns 1 and .....(we get data from server), * 2 if there is no entry for the queue(we dont get data from server) and 3 if statusCode not 200 * * @return int that shows result interpretation *///from w ww.j a v a2s . co m public int getVaccinationQueueByDateAndUser() { final StringBuilder webServiceUrl = createWebServiceURL("", GET_VACCINATION_QUEUE_BY_DATE_AND_USER); webServiceUrl.append("?date=") .append(new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())) .append("&userId=").append(getLOGGED_IN_USER_ID()); Log.e("getVaccQueueByDt&Usr", webServiceUrl.toString()); try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(webServiceUrl.toString()); Utils.writeNetworkLogFileOnSD( Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + webServiceUrl.toString()); httpGet.setHeader("Authorization", "Basic " + Base64 .encodeToString((LOGGED_IN_USERNAME + ":" + LOGGED_IN_USER_PASS).getBytes(), Base64.NO_WRAP)); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { Utils.writeNetworkLogFileOnSD(Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + " StatusCode " + httpResponse.getStatusLine().getStatusCode() + " ReasonPhrase " + httpResponse.getStatusLine().getReasonPhrase() + " ProtocolVersion " + httpResponse.getStatusLine().getProtocolVersion()); return 3; } InputStream inputStream = httpResponse.getEntity().getContent(); String responseAsString = Utils.getStringFromInputStream(inputStream); Utils.writeNetworkLogFileOnSD( Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + responseAsString); JSONArray jarr = new JSONArray(responseAsString); DatabaseHandler db = getDatabaseInstance(); String childBarcodesNotInDB = ""; for (int i = 0; i < jarr.length(); i++) { JSONObject jobj = jarr.getJSONObject(i); if (db.isBarcodeInChildTable(jobj.getString("BarcodeId"))) { String dateNow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ") .format(new Date(Long.parseLong(jobj.getString("Date").substring(6, 19)))); ContentValues cv = new ContentValues(); cv.put(SQLHandler.VaccinationQueueColumns.CHILD_ID, db.getChildIdByBarcode(jobj.getString("BarcodeId"))); cv.put(SQLHandler.VaccinationQueueColumns.DATE, dateNow); db.addChildToVaccinationQueue(cv); } else { if (childBarcodesNotInDB.length() > 0) childBarcodesNotInDB += ","; childBarcodesNotInDB += jobj.getString("BarcodeId"); } } if (childBarcodesNotInDB.length() > 0) { getChildByBarcodeList(childBarcodesNotInDB); } return 1; } catch (JsonGenerationException e) { e.printStackTrace(); return 2; } catch (JsonMappingException e) { e.printStackTrace(); return 2; } catch (IOException e) { e.printStackTrace(); return 3; } catch (JSONException e) { e.printStackTrace(); return 2; } }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
/** * Parsing data from Server after the First login in intervals *///w w w .j a v a 2 s . c o m public void intervalGetChildrenByHealthFacilitySinceLastLogin() { String url = WCF_URL + "ChildManagement.svc/GetChildrenByHealthFacilitySinceLastLoginV1?idUser=" + getLOGGED_IN_USER_ID(); Log.e("SinceLastLogin", "GetChildrenByHealthFacilitySinceLastLogin url is: " + url); ChildCollector2 objects2 = new ChildCollector2(); try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); Utils.writeNetworkLogFileOnSD( Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + url.toString()); httpGet.setHeader("Authorization", "Basic " + Base64 .encodeToString((LOGGED_IN_USERNAME + ":" + LOGGED_IN_USER_PASS).getBytes(), Base64.NO_WRAP)); HttpResponse httpResponse = httpClient.execute(httpGet); InputStream inputStream = httpResponse.getEntity().getContent(); String response = Utils.getStringFromInputStream(inputStream); Log.e("SinceLastLogin", "responce is: " + response); Utils.writeNetworkLogFileOnSD(Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + response); ObjectMapper mapper = new ObjectMapper(); objects2 = mapper.readValue(response, new TypeReference<List<ChildCollector>>() { }); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { Log.d("coze", "before saving to the database"); if (addChildVaccinationEventVaccinationAppointment(objects2)) { Log.d("coze", "about to re login"); loginRequest(); objects2 = null; // clearing references so that it can be identified as GC material more easilly; } } }