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.letsgood.synergykitsdkandroid.requestmethods.Post.java
@Override public BufferedReader execute() { String jSon = null;/*from w w w . ja v a 2 s .co m*/ String uri = null; //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 accept httpURLConnection.addRequestProperty(PROPERTY_ACCEPT, ACCEPT_APPLICATION_VALUE); //set property accept httpURLConnection.addRequestProperty(PROPERTY_CONTENT_TYPE, ACCEPT_APPLICATION_VALUE); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); 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()); httpURLConnection.connect(); //write data if (object != null) { jSon = GsonWrapper.getGson().toJson(object); dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); dataOutputStream.write(jSon.getBytes(CHARSET)); dataOutputStream.flush(); dataOutputStream.close(); } statusCode = httpURLConnection.getResponseCode(); //get status code //read stream if (statusCode >= HttpURLConnection.HTTP_OK && statusCode < HttpURLConnection.HTTP_MULT_CHOICE) { return readStream(httpURLConnection.getInputStream()); } else { return readStream(httpURLConnection.getErrorStream()); } } catch (Exception e) { statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE; e.printStackTrace(); return null; } }
From source file:com.letsgood.synergykitsdkandroid.requestmethods.Patch.java
@Override public BufferedReader execute() { String jSon = null;//from w w w. j a v a2 s . c om String uri = null; //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 accept httpURLConnection.addRequestProperty(PROPERTY_ACCEPT, ACCEPT_APPLICATION_VALUE); //set property accept httpURLConnection.addRequestProperty(PROPERTY_CONTENT_TYPE, ACCEPT_APPLICATION_VALUE); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); 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()); httpURLConnection.connect(); //write data if (object != null) { jSon = GsonWrapper.getGson().toJson(object); dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); dataOutputStream.write(jSon.getBytes(CHARSET)); dataOutputStream.flush(); dataOutputStream.close(); } statusCode = httpURLConnection.getResponseCode(); //get status code //read stream if (statusCode >= HttpURLConnection.HTTP_OK && statusCode < HttpURLConnection.HTTP_MULT_CHOICE) { return readStream(httpURLConnection.getInputStream()); } else { return readStream(httpURLConnection.getErrorStream()); } } catch (Exception e) { statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE; e.printStackTrace(); return null; } }
From source file:org.kde.kdeconnect.Helpers.SecurityHelpers.RsaHelper.java
public static NetworkPackage encrypt(NetworkPackage np, PublicKey publicKey) throws GeneralSecurityException, JSONException { String serialized = np.serialize(); int chunkSize = 128; Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); JSONArray chunks = new JSONArray(); while (serialized.length() > 0) { if (serialized.length() < chunkSize) { chunkSize = serialized.length(); }//from ww w . ja va2 s. com String chunk = serialized.substring(0, chunkSize); serialized = serialized.substring(chunkSize); byte[] chunkBytes = chunk.getBytes(Charset.defaultCharset()); byte[] encryptedChunk; encryptedChunk = cipher.doFinal(chunkBytes); chunks.put(Base64.encodeToString(encryptedChunk, Base64.NO_WRAP)); } //Log.i("NetworkPackage", "Encrypted " + chunks.length()+" chunks"); NetworkPackage encrypted = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_ENCRYPTED); encrypted.set("data", chunks); encrypted.setPayload(np.getPayload(), np.getPayloadSize()); return encrypted; }
From source file:com.harshad.linconnectclient.NotificationUtilities.java
public static boolean sendData(Context c, Notification n, String packageName) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); ConnectivityManager connManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); // Check Wifi state, whether notifications are enabled globally, and // whether notifications are enabled for specific application if (prefs.getBoolean("pref_toggle", true) && prefs.getBoolean(packageName, true) && mWifi.isConnected()) { String ip = prefs.getString("pref_ip", "0.0.0.0:9090"); // Magically extract text from notification ArrayList<String> notificationData = NotificationUtilities.getNotificationText(n); // Use PackageManager to get application name and icon final PackageManager pm = c.getPackageManager(); ApplicationInfo ai;//from w w w . j a v a 2 s . c om try { ai = pm.getApplicationInfo(packageName, 0); } catch (final NameNotFoundException e) { ai = null; } String notificationBody = ""; String notificationHeader = ""; // Create header and body of notification if (notificationData.size() > 0) { notificationHeader = notificationData.get(0); if (notificationData.size() > 1) { notificationBody = notificationData.get(1); } } else { return false; } for (int i = 2; i < notificationData.size(); i++) { notificationBody += "\n" + notificationData.get(i); } // Append application name to body if (pm.getApplicationLabel(ai) != null) { if (notificationBody.isEmpty()) { notificationBody = "via " + pm.getApplicationLabel(ai); } else { notificationBody += " (via " + pm.getApplicationLabel(ai) + ")"; } } // Setup HTTP request MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); // If the notification contains an icon, use it if (n.largeIcon != null) { entity.addPart("notificon", new InputStreamBody(ImageUtilities.bitmapToInputStream(n.largeIcon), "drawable.png")); } // Otherwise, use the application's icon else { entity.addPart("notificon", new InputStreamBody( ImageUtilities.bitmapToInputStream( ImageUtilities.drawableToBitmap(pm.getApplicationIcon(ai))), "drawable.png")); } HttpPost post = new HttpPost("http://" + ip + "/notif"); post.setEntity(entity); try { post.addHeader("notifheader", Base64.encodeToString(notificationHeader.getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP)); post.addHeader("notifdescription", Base64.encodeToString(notificationBody.getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP)); } catch (UnsupportedEncodingException e) { post.addHeader("notifheader", Base64.encodeToString(notificationHeader.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); post.addHeader("notifdescription", Base64.encodeToString(notificationBody.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); } // Send HTTP request HttpClient client = new DefaultHttpClient(); HttpResponse response; try { response = client.execute(post); String html = EntityUtils.toString(response.getEntity()); if (html.contains("true")) { return true; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:de.aw.monma.hbci.FragmentMasterPassword.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); passwordView = view.findViewById(R.id.etPassword); passwordView.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override/*w w w . j ava 2s .c om*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { onClick(passwordView); return true; } return false; } }); newPasswordView = view.findViewById(R.id.etNewPassword); AWApplication.Log("Passwort Abfrage gestartet"); String key = prefs.getString(getString(R.string.key), null); if (key != null) { mKey = Base64.decode(key, Base64.NO_WRAP); } if (mKey != null) { newPasswordView.setVisibility(View.GONE); } view.findViewById(R.id.loginBtn).setOnClickListener(this); }
From source file:org.riksa.syncmute.ParseTools.java
/** * Get channel name. Channel name is a salted SHA-256 hash of username+channename (from settings) * * @return Base64 encoded SHA-256 salted hash *//* w w w .j a v a2 s. com*/ protected String getChannel() { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String userName = preferences.getString("preferences_username", "DEFAULT"); String channelName = preferences.getString("preferences_channel", "DEFAULT"); Log.d(TAG, "hashing username=" + userName); Log.d(TAG, "hashing channelName=" + channelName); byte[] digest = doHash(DIGEST_ALGORITHM, SALT, userName.getBytes("UTF-8"), channelName.getBytes("UTF-8")); // Base64 encode without padding. Padded channel name is invalid (alphanumerics only) String base64Digest = Base64.encodeToString(digest, Base64.NO_WRAP | Base64.NO_PADDING); Log.d(TAG, "base64Digest=" + base64Digest); return base64Digest; } catch (NoSuchAlgorithmException e) { Log.e(TAG, e.getMessage(), e); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage(), e); } return "DEFAULT"; }
From source file:com.letsgood.synergykitsdkandroid.requestmethods.PostFile.java
@Override public BufferedReader execute() { String uri = null;/* w ww . ja va 2 s. co 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 accept httpURLConnection.addRequestProperty(PROPERTY_ACCEPT, ACCEPT_APPLICATION_VALUE); //set property accept httpURLConnection.addRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY); httpURLConnection.addRequestProperty("Connection", "Keep-Alive"); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); 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()); httpURLConnection.connect(); //write data if (data != null) { dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); dataOutputStream.writeBytes(TWO_HYPHENS + BOUNDARY + CRLF); dataOutputStream.writeBytes("Content-Disposition: form-data; name=\"" + ATTACHMENT_NAME + "\";filename=\"" + ATTACHMENT_FILE_NAME + "\"" + CRLF); dataOutputStream.writeBytes(CRLF); dataOutputStream.write(data); dataOutputStream.writeBytes(CRLF); dataOutputStream.writeBytes(TWO_HYPHENS + BOUNDARY + TWO_HYPHENS + CRLF); dataOutputStream.flush(); dataOutputStream.close(); } statusCode = httpURLConnection.getResponseCode(); //get status code SynergykitLog.print(Integer.toString(statusCode)); //read stream if (statusCode >= HttpURLConnection.HTTP_OK && statusCode < HttpURLConnection.HTTP_MULT_CHOICE) { return readStream(httpURLConnection.getInputStream()); } else { return readStream(httpURLConnection.getErrorStream()); } } catch (Exception e) { statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE; e.printStackTrace(); return null; } }
From source file:com.letsgood.synergykitsdkandroid.requestmethods.Get.java
public InputStream halfExecute() { String uri = null;//w ww.ja v a2 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("Cache-Control", "max-stale=120"); httpURLConnection.addRequestProperty(PROPERTY_CONTENT_TYPE, ACCEPT_APPLICATION_VALUE); httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(true); httpURLConnection.setDefaultUseCaches(true); if (isAuthorizationEnabled()) { 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 httpURLConnection.getInputStream(); } else { return httpURLConnection.getErrorStream(); } } catch (Exception e) { statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE; e.printStackTrace(); return null; } }
From source file:com.honeywell.printer.net.autobaln_websocket.WebSocketWriter.java
/** * Create new key for WebSockets handshake. * * @return WebSockets handshake key (Base64 encoded). *//*from w w w . j av a 2 s . c om*/ private String newHandshakeKey() { final byte[] ba = new byte[16]; mRandom.nextBytes(ba); return Base64.encodeToString(ba, Base64.NO_WRAP); }
From source file:com.pbi.dvb.websocket.WebSocketWriter.java
/** * Create new key for WebSockets handshake. * * @return WebSockets handshake key (Base64 encoded). *//*from w w w.jav a 2s . c om*/ public String newHandshakeKey() { final byte[] ba = new byte[16]; mRng.nextBytes(ba); return Base64.encodeToString(ba, Base64.NO_WRAP); }