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.charabia.SmsViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create the list fragment and add it as our sole content. if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) { CursorLoaderListFragment listFragment = new CursorLoaderListFragment(); getSupportFragmentManager().beginTransaction().add(android.R.id.content, listFragment).commit(); }//from ww w .j a v a 2s. c om try { String texte = "bonjour"; byte[] data = tools.encrypt("15555215556", texte.getBytes()); Log.v("CHARABIA", "data=" + Base64.encodeToString(data, Base64.NO_WRAP)); Log.v("CHARABIA", "data=" + Tools.bytesToHex(data)); String result = new String(tools.decrypt("15555215556", data)); Log.v("CHARABIA", "result=" + result); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.restswitch.controlpanel.MainActivity.java
private void sendDevice(String devid, String host, String msg, String pwdHash) { try {//from w ww . j a v a2 s . c om final long utcStart = System.currentTimeMillis(); String b32UntilUtc = B32Coder.encodeDatetimeNow(8000); // valid for 8 sec String method = "PUT"; String uri = ("/pub/" + devid); String val = (method + uri + msg + b32UntilUtc); String b64Hash = null; try { Mac hmacSha256 = Mac.getInstance("HmacSHA256"); hmacSha256.init(new javax.crypto.spec.SecretKeySpec(pwdHash.getBytes("utf-8"), "HmacSHA256")); byte[] hash = hmacSha256.doFinal(val.getBytes("UTF-8")); b64Hash = Base64.encodeToString(hash, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP); } catch (Exception ex) { alertError("Invalid password, verify app settings."); return; } Properties headers = new Properties(); headers.setProperty("x-body", msg); headers.setProperty("x-auth1", b32UntilUtc); headers.setProperty("x-auth2", b64Hash); AjaxTask ajaxTask = new AjaxTask(); ajaxTask.putAjaxEventHandler(this); // // use to set a custom ca // boolean rc = ajaxTask.putRootCaCert(rootCa, true); // if(!rc) { // alertError("Failed to initialize network task."); // return; // } AjaxTask.Data data = new AjaxTask.Data(); data.param1 = devid; data.param2 = utcStart; ajaxTask.invoke("http", host, uri, method, headers, msg, data); } catch (Exception ex) { alertError(ex.getMessage()); } }
From source file:android.locationprivacy.algorithm.Webservice.java
@Override public Location obfuscate(Location location) { // We do it this way to run network connection in main thread. This // way is not the normal one and does not comply to best practices, // but the main thread must wait for the obfuscation service reply anyway. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);/*from w ww. j a v a2 s .c om*/ final String HOST_ADDRESS = configuration.getString("host"); String username = configuration.getString("username"); String password = configuration.getString("secret_password"); Location newLoc = new Location(location); double lat = location.getLatitude(); double lon = location.getLongitude(); String urlString = HOST_ADDRESS; urlString += "?lat=" + lat; urlString += "&lon=" + lon; URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { Log.e(TAG, "Error: could not build URL"); Log.e(TAG, e.getMessage()); return null; } HttpsURLConnection connection = null; JSONObject json = null; InputStream is = null; try { connection = (HttpsURLConnection) url.openConnection(); connection.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); connection.setRequestProperty("Authorization", "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP)); is = connection.getInputStream(); } catch (IOException e) { Log.e(TAG, "Error while connectiong to " + url.toString()); Log.e(TAG, e.getMessage()); return null; } BufferedReader reader = new BufferedReader(new InputStreamReader(is)); try { String line = reader.readLine(); System.out.println("Line " + line); json = new JSONObject(line); newLoc.setLatitude(json.getDouble("lat")); newLoc.setLongitude(json.getDouble("lon")); } catch (IOException e) { Log.e(TAG, "Error: could not read from BufferedReader"); Log.e(TAG, e.getMessage()); return null; } catch (JSONException e) { Log.e(TAG, "Error: could not read from JSON"); Log.e(TAG, e.getMessage()); return null; } connection.disconnect(); return newLoc; }
From source file:com.samknows.measurement.util.LoginHelper.java
public static String getCredentialsEncoded() { return Base64.encodeToString((getCredentials()).getBytes(), Base64.NO_WRAP); }
From source file:org.xwiki.android.authenticator.rest.XWikiConnector.java
public static String userSignIn(String server, String user, String pass, String authType) throws Exception { Log.d("xwiki", "userSignIn"); DefaultHttpClient httpClient = new DefaultHttpClient(); String url = server + "/rest/"; HttpGet httpGet = new HttpGet(url); httpGet.addHeader("Authorization", "Basic " + Base64.encodeToString((user + ':' + pass).getBytes(), Base64.NO_WRAP)); HttpParams params = new BasicHttpParams(); params.setParameter("username", user); params.setParameter("password", pass); httpGet.setParams(params);//from w w w . ja v a 2 s. c o m HttpResponse response = httpClient.execute(httpGet); int error = response.getStatusLine().getStatusCode(); if (error != 200) { throw new Exception("Error signing-in [" + url + "] with error code [" + error + "]"); } return null; }
From source file:ca.ualberta.app.activity.CreateQuestionActivity.java
@Override public void onStart() { super.onStart(); Intent intent = getIntent();// w w w.j av a 2 s .co m if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { questionID = extras.getLong(QUESTION_ID); String questionTitle = extras.getString(QUESTION_TITLE); String questionContent = extras.getString(QUESTION_CONTENT); try { byte[] imageByteArray = Base64.decode(extras.getByteArray(IMAGE), Base64.NO_WRAP); image = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length); scaleImage(THUMBIMAGESIZE, THUMBIMAGESIZE, true); imageView.setVisibility(View.VISIBLE); imageView.setImageBitmap(imageThumb); } catch (Exception e) { } titleText.setText(questionTitle); contentText.setText(questionContent); edit = true; } } }
From source file:com.hmsoft.libcommon.gopro.GoProController.java
private void logCommandAndResponse(String url, byte[] response) { String responseStr = Base64.encodeToString(response, 0, response.length > 512 ? 512 : response.length, Base64.NO_WRAP | Base64.URL_SAFE); Logger.info(TAG, removePassword(url) + " = " + responseStr); }
From source file:com.securekey.sdk.sample.AuthenticateDeviceActivity.java
/** * Implementation of Briidge.AuthenticateDeviceListener.authenticateDeviceComplete * or Briidge.AuthenticateDeviceReturnJWSListener.authenticateDeviceComplete *//* w w w .j a v a2 s . c o m*/ @Override public void authenticateDeviceComplete(int status, String txnId) { dismissProgressDialog(); if (status == Briidge.STATUS_OK) { if (txnId != null) { if (this.jwsExpected) { // The JWT should be provide to a third party to be verify // It could be parse to see what's inside dismissProgressDialog(); String[] jwtSegment = getJWSSegments(txnId); try { final StringBuilder message = new StringBuilder(); message.append(new String(Base64.decode(jwtSegment[0], Base64.NO_WRAP), "UTF-8") + "\n"); message.append( new String(Base64.decode(jwtSegment[1], Base64.NO_WRAP), "UTF-8") + "\n\n\n"); showDialog(message.toString()); // JWT could be check on server side verifyJWT(txnId); } catch (UnsupportedEncodingException e) { Log.e(VerifyQuickCodeActivity.class.toString(), e.getMessage()); } } else { getDeviceId(txnId); } } else { showDialog("Error: null data!"); } } else if (status == Briidge.STATUS_CONNECTIVITY_ERROR) { showDialog("Error connecting to server!"); } else { showDialog("Error processing request!"); } }
From source file:gowtham.com.desknote.MyListener.java
private String bitmap2Base64(Bitmap b) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); //Bitmap gray = toGrayscale(b); // Windows needs atleast 48x48 image, otherwise, notification is not shown Bitmap smaller = b.createScaledBitmap(b, 48, 48, false); // PNG is lossless. So, quality setting is unused smaller.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] buf = baos.toByteArray(); return new String(Base64.encode(buf, Base64.NO_WRAP)); }
From source file:com.megster.cordova.ble.central.Peripheral.java
static JSONObject byteArrayToJSON(byte[] bytes) throws JSONException { JSONObject object = new JSONObject(); object.put("CDVType", "ArrayBuffer"); object.put("data", Base64.encodeToString(bytes, Base64.NO_WRAP)); return object; }