List of usage examples for android.util Base64 DEFAULT
int DEFAULT
To view the source code for android.util Base64 DEFAULT.
Click Source Link
From source file:com.samknows.measurement.net.Connection.java
/** Get the HTTP digest authentication. Uses Base64 to encode credentials. * /*from ww w . ja v a 2 s. c o m*/ * @return String */ public String getCredentials() { return new String(Base64.encode((mUsername + ":" + mPassword).getBytes(), Base64.DEFAULT)); }
From source file:com.murrayc.galaxyzoo.app.provider.client.ZooniverseClient.java
private String generateAuthorizationHeader(final String authName, final String authApiKey) { //See the similar code in Zooniverse's user.coffee source code: //https://github.com/zooniverse/Zooniverse/blob/master/src/models/user.coffee#L49 final String str = authName + ":" + authApiKey; byte[] asBytes = null; try {// w ww . j a v a 2 s.co m asBytes = str.getBytes(Utils.STRING_ENCODING); } catch (final UnsupportedEncodingException e) { //This is incredibly unlikely for the UTF-8 encoding, //so we just log it instead of trying to recover from it. Log.error("generateAuthorizationHeader(): String.getBytes() failed", e); return null; } return "Basic " + Base64.encodeToString(asBytes, Base64.DEFAULT); }
From source file:com.leanplum.internal.WebSocketClient.java
private String createSecret() { byte[] nonce = new byte[16]; for (int i = 0; i < 16; i++) { nonce[i] = (byte) (Math.random() * 256); }/*from w w w . j a v a2 s . c o m*/ return Base64.encodeToString(nonce, Base64.DEFAULT).trim(); }
From source file:com.codebutler.farebot.card.felica.FelicaCard.java
@Override public Element toXML() throws Exception { Element root = super.toXML(); Document doc = root.getOwnerDocument(); Element idmElement = doc.createElement("idm"); idmElement.setTextContent(Base64.encodeToString(mIDm.getBytes(), Base64.DEFAULT)); root.appendChild(idmElement);/*w ww. ja v a2 s. com*/ Element pmmElement = doc.createElement("pmm"); pmmElement.setTextContent(Base64.encodeToString(mPMm.getBytes(), Base64.DEFAULT)); root.appendChild(pmmElement); Element systemsElement = doc.createElement("systems"); for (FelicaSystem system : mSystems) { Element systemElement = doc.createElement("system"); systemElement.setAttribute("code", String.valueOf(system.getCode())); Element servicesElement = doc.createElement("services"); for (FelicaService service : system.getServices()) { Element serviceElement = doc.createElement("service"); serviceElement.setAttribute("code", String.valueOf(service.getServiceCode())); Element blocksElement = doc.createElement("blocks"); for (FelicaBlock block : service.getBlocks()) { Element blockElement = doc.createElement("block"); blockElement.setAttribute("address", String.valueOf(block.getAddress())); blockElement.setTextContent(Base64.encodeToString(block.getData(), Base64.DEFAULT)); blocksElement.appendChild(blockElement); } serviceElement.appendChild(blocksElement); servicesElement.appendChild(serviceElement); } systemElement.appendChild(servicesElement); systemsElement.appendChild(systemElement); } root.appendChild(systemsElement); return root; }
From source file:app.sunstreak.yourpisd.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_new); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar);//from w ww . ja v a 2 s.co m } final SharedPreferences sharedPrefs = getPreferences(Context.MODE_PRIVATE); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); height = size.y; mLoginFormView = findViewById(R.id.login_form); mLoginStatusView = (LinearLayout) findViewById(R.id.login_status); mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message); if (DateHelper.isAprilFools()) { LinearLayout container = (LinearLayout) mLoginFormView.findViewById(R.id.container); ImageView logo = (ImageView) container.findViewById(R.id.logo); InputStream is; try { is = getAssets().open("doge.png"); logo.setImageBitmap(BitmapFactory.decodeStream(is)); is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } mAutoLogin = sharedPrefs.getBoolean("auto_login", false); System.out.println(mAutoLogin); session = ((YPApplication) getApplication()).session; try { boolean refresh = getIntent().getExtras().getBoolean("Refresh"); if (refresh) { mEmail = session.getUsername(); mPassword = session.getPassword(); showProgress(true); mAuthTask = new UserLoginTask(); mAuthTask.execute((Void) null); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0); } else mLoginFormView.setVisibility(View.VISIBLE); } catch (NullPointerException e) { // Keep going. } if (sharedPrefs.getBoolean("patched", false)) { SharedPreferences.Editor editor = sharedPrefs.edit(); editor.remove("password"); editor.putBoolean("patched", true); editor.commit(); } if (!sharedPrefs.getBoolean("AcceptedUserAgreement", false)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getResources().getString(R.string.user_agreement_title)); builder.setMessage(getResources().getString(R.string.user_agreement)); // Setting Positive "Yes" Button builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sharedPrefs.edit().putBoolean("AcceptedUserAgreement", true).commit(); dialog.cancel(); } }); // Setting Negative "NO" Button builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Write your code here to invoke NO event sharedPrefs.edit().putBoolean("AcceptedUserAgreement", false).commit(); Toast.makeText(LoginActivity.this, "Quitting app", Toast.LENGTH_SHORT).show(); finish(); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); } // Set up the remember_password CheckBox mRememberPasswordCheckBox = (CheckBox) findViewById(R.id.remember_password); mRememberPasswordCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mRememberPassword = isChecked; } }); mRememberPassword = sharedPrefs.getBoolean("remember_password", false); mRememberPasswordCheckBox.setChecked(mRememberPassword); // Set up the auto_login CheckBox mAutoLoginCheckBox = (CheckBox) findViewById(R.id.auto_login); mAutoLoginCheckBox.setChecked(mAutoLogin); mAutoLoginCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton button, boolean isChecked) { mAutoLogin = isChecked; if (isChecked) { mRememberPasswordCheckBox.setChecked(true); } } }); // Set up the login form. mEmailView = (EditText) findViewById(R.id.email); mPasswordView = (EditText) findViewById(R.id.password); mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (id == R.id.login || id == EditorInfo.IME_NULL) { attemptLogin(); return true; } return false; } }); //Load stored username/password mEmailView.setText(sharedPrefs.getString("email", mEmail)); mPasswordView.setText(new String(Base64.decode(sharedPrefs.getString("e_password", ""), Base64.DEFAULT))); // If the password was not saved, give focus to the password. if (mPasswordView.getText().equals("")) mPasswordView.requestFocus(); mLoginFormView = findViewById(R.id.login_form); mLoginStatusView = (LinearLayout) findViewById(R.id.login_status); mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message); findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { attemptLogin(); } }); findViewById(R.id.sign_in_button).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0); return false; } }); mLoginFormView.setVisibility(View.VISIBLE); // Login if auto-login is checked. if (mAutoLogin) attemptLogin(); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java
@Override public Pair<JSONObject, byte[]> handleOutgoing(JSONObject json) { byte[] bytes = Base64.decode(json.optString(DATA), Base64.DEFAULT); json.remove(DATA);//from w ww .j a v a 2s .c om return new Pair<JSONObject, byte[]>(json, bytes); }
From source file:pl.selvin.android.syncframework.content.TableInfo.java
@SuppressLint("NewApi") final public void SyncJSON(final HashMap<String, Object> hval, final Metadata meta, final SQLiteDatabase db) { int i = 0;/*from www . ja v a2 s. co m*/ vals.clear(); for (; i < columns.length; i++) { String column = columns[i].name; switch (columns[i].type) { case ColumnType.BLOB: final String str = (String) hval.get(column); if (str != null) vals.put(column, Base64.decode(str, Base64.DEFAULT)); break; case ColumnType.BOOLEAN: case ColumnType.INTEGER: vals.put(column, (Long) hval.get(column)); break; case ColumnType.DATETIME: String date = (String) hval.get(column); if (date != null) { date = sdf.format(new Date(Long.parseLong(date.substring(6, date.length() - 2)))); } vals.put(column, date); break; case ColumnType.NUMERIC: Object obj = hval.get(column); if (obj instanceof Double) vals.put(column, (Double) obj); else vals.put(column, (Long) obj); break; default: vals.put(column, (String) hval.get(column)); break; } } vals.put(_.uri, meta.uri); vals.put(_.tempId, (String) null); vals.put(_.isDirty, 0); if (meta.tempId != null) { db.update(name, vals, _.tempIdP, new String[] { meta.tempId }); } else { db.replace(name, null, vals); } }
From source file:ch.bfh.evoting.alljoyn.MessageEncrypter.java
/** * Set the salt/*from w w w.j ava2 s. c o m*/ * @param salt the Base64 encoded salt */ public void setSalt(String salt) { byte[] tempSalt = Base64.decode(salt, Base64.DEFAULT); if (this.saltShortDigest.equals(getSaltShortDigest(tempSalt))) { Log.d(TAG, "received salt digest is " + saltShortDigest + " and computed digest from received salt is " + getSaltShortDigest(tempSalt)); this.salt = tempSalt; Log.d(TAG, "Saving salt " + salt); this.derivateKey(password.toCharArray()); } else { Intent intent = new Intent("probablyWrongDecryptionKeyUsed"); intent.putExtra("type", "salt"); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); Log.e(TAG, "Salt is false!"); } }
From source file:com.chaosinmotion.securechat.messages.SCMessageQueue.java
/** * Internal routine for polling for messages, used if we cannot open * a socket for notifications./*www . j av a 2s. c o m*/ */ private void pollForMessages() { if (receiving) return; receiving = true; /* * Poll messages */ JSONObject obj = new JSONObject(); try { obj.put("deviceid", SCRSAManager.shared().getDeviceUUID()); } catch (JSONException e) { // Should never happen } SCNetwork.get().request("messages/getmessages", obj, false, this, new SCNetwork.ResponseInterface() { @Override public void responseResult(SCNetwork.Response response) { if (response.isSuccess()) { JSONArray a = response.getData().optJSONArray("messages"); int i, len = a.length(); for (i = 0; i < len; ++i) { JSONObject d = a.optJSONObject(i); int messageID = d.optInt("messageID"); int senderID = d.optInt("senderID"); String senderName = d.optString("senderName"); String received = d.optString("received"); Date timestamp = DateUtils.parseServerDate(received); boolean toFlag = d.optBoolean("toflag"); byte[] data = Base64.decode(d.optString("message"), Base64.DEFAULT); insertMessage(senderID, senderName, toFlag, messageID, timestamp, data); } } receiving = false; } }); }
From source file:com.partypoker.poker.engagement.reach.EngagementReachInteractiveContent.java
/** * Get notification image for in app notifications. For system notification this field corresponds * to the large icon (displayed only on Android 3+). * @return notification image./* w w w . jav a2 s . com*/ */ public Bitmap getNotificationImage() { /* Decode as bitmap now if not already done */ if (mNotificationImageString != null && mNotificationImage == null) { /* Decode base 64 then decode as a bitmap */ byte[] data = Base64.decode(mNotificationImageString, Base64.DEFAULT); if (data != null) try { mNotificationImage = BitmapFactory.decodeByteArray(data, 0, data.length); } catch (OutOfMemoryError e) { /* Abort */ } /* On any error, don't retry next time */ if (mNotificationImage == null) mNotificationImageString = null; } return mNotificationImage; }