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.redwoodsystems.android.apps.utils.HttpUtil.java
public static String getAuthHeader(String userName, String password) { String s = userName + ":" + password; String authHdr = "Basic " + Base64.encode(s.getBytes(), Base64.DEFAULT); return authHdr; }
From source file:com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.internal.JSONRecordAdapter.java
/** * @param source the PutRecordRequest to that will be stored * @return JSONObject the json representation of the request *///from w w w .ja v a 2 s .com public JSONObject translateFromRecord(PutRecordRequest source) { if (null == source) { logger.i("The Record provided was null"); return null; } if (source.getData() == null || source.getPartitionKey() == null || source.getPartitionKey().isEmpty() || source.getStreamName() == null || source.getStreamName().isEmpty()) { throw new AmazonClientException("RecordRequests must specify a partition key, stream name, and data"); } if (!source.getData().hasArray()) { throw new AmazonClientException("ByteBuffer must be based on array for proper storage"); } JSONObject recordJson = new JSONObject(); try { recordJson.put(DATA_FIELD_KEY, Base64.encodeToString(source.getData().array(), Base64.DEFAULT)); recordJson.put(STREAM_NAME_FIELD, source.getStreamName()); recordJson.put(PARTITION_KEY_FIELD, source.getPartitionKey()); recordJson.putOpt(EXPLICIT_HASH_FIELD, source.getExplicitHashKey()); recordJson.putOpt(SEQUENCE_NUMBER_FIELD, source.getSequenceNumberForOrdering()); } catch (JSONException e) { throw new AmazonClientException("Unable to convert KinesisRecord to JSON " + e.getMessage()); } return recordJson; }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.security.DefaultJSONSignerTests.java
public void testSigning() throws JSONException { JSONObject testPayload = new JSONObject(); testPayload.put("testName", "testValue"); KeyPair keyPair = generateRandomKeyPair(); String result = ""; try {/* w w w.ja va2 s .c o m*/ result = jsonSigner.sign(keyPair, testPayload); } catch (Exception e) { fail(); e.printStackTrace(); } String[] splitedValues = result.split("\\."); //check for the correct structure assertEquals(3, splitedValues.length); //check for the correct structure of the first part JSONObject firstPart = new JSONObject(new String(Base64.decode(splitedValues[0], Base64.DEFAULT))); assertEquals("RS256", firstPart.get("alg")); assertNotNull(firstPart.get("jpk")); JSONObject jpkJSONObject = new JSONObject(firstPart.getString("jpk")); //test jpk JSON assertEquals("RSA", jpkJSONObject.getString("alg")); assertNotNull(jpkJSONObject.getString("mod")); assertNotNull(jpkJSONObject.getString("exp")); //check for the correct structure of the second parts JSONObject secondPart = new JSONObject(new String(Base64.decode(splitedValues[1], Base64.DEFAULT))); assertEquals("testValue", secondPart.getString("testName")); }
From source file:de.stadtrallye.rallyesoft.net.AuthProvider.java
private String getBasicAuth(byte[] username, byte[] password) { if (username == null) { username = new byte[0]; }//from w ww . j av a2 s.c om if (password == null) { password = new byte[0]; } final byte[] usernamePassword = new byte[username.length + password.length + 1]; System.arraycopy(username, 0, usernamePassword, 0, username.length); usernamePassword[username.length] = ':'; System.arraycopy(password, 0, usernamePassword, username.length + 1, password.length); return "Basic " + Base64.encodeToString(usernamePassword, Base64.DEFAULT); }
From source file:illab.nabal.util.SecurityHelper.java
/** * Get HMACSHA1-encoded OAuth 1.0a signature string. * /*w w w. j a v a2 s . c o m*/ * @param secretKey - secret key to encode basestring with * @param baseString - signature base string * @return oauthSignature - HMAC-SHA1 encoded signature string * @throws Exception */ public static String getHmacSha1Signature(String secretKey, String baseString) throws Exception { String oauthSignature = null; // #################### IMPORTANT #################### // the secret key is the concatenated values (each first encoded per Parameter // Encoding) of the Consumer Secret and Token Secret, separated by an '&' character // (ASCII code 38) even if empty. if (StringHelper.isAllFull(secretKey, baseString) == true) { byte[] keyBytes = secretKey.getBytes(HTTP.UTF_8); SecretKey keySpec = new SecretKeySpec(keyBytes, HMAC_SHA1); Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(keySpec); oauthSignature = new String(Base64.encode(mac.doFinal(baseString.getBytes(HTTP.UTF_8)), Base64.DEFAULT), HTTP.UTF_8).trim(); } return oauthSignature; }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
private static void addToInstallQueue(SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) { synchronized (sLock) { try {/*from ww w . j a v a 2s. c om*/ JSONStringer json = new JSONStringer().object().key(DATA_INTENT_KEY).value(info.data.toUri(0)) .key(LAUNCH_INTENT_KEY).value(info.launchIntent.toUri(0)).key(NAME_KEY).value(info.name); if (info.icon != null) { byte[] iconByteArray = ItemInfo.flattenBitmap(info.icon); json = json.key(ICON_KEY) .value(Base64.encodeToString(iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); } if (info.iconResource != null) { json = json.key(ICON_RESOURCE_NAME_KEY).value(info.iconResource.resourceName); json = json.key(ICON_RESOURCE_PACKAGE_NAME_KEY).value(info.iconResource.packageName); } json = json.endObject(); SharedPreferences.Editor editor = sharedPrefs.edit(); if (DBG) Log.d(TAG, "Adding to APPS_PENDING_INSTALL: " + json); addToStringSet(sharedPrefs, editor, APPS_PENDING_INSTALL, json.toString()); editor.commit(); } catch (org.json.JSONException e) { Log.d(TAG, "Exception when adding shortcut: " + e); } } }
From source file:com.coodesoft.notee.MyImageGetter.java
@Override public Drawable getDrawable(String source) { Drawable d = null;// w ww. ja v a2s . co m String strSrcLeft5 = source.substring(0, 5); // data if (strSrcLeft5.equalsIgnoreCase("data:")) { InputStream is = new ByteArrayInputStream(source.getBytes()); //d = Drawable.createFromStream(is, null); //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); //Bitmap dBitmap = BitmapFactory.decodeByteArray(data, 0, length); int nPosComma = source.indexOf(','); if (nPosComma > 0) { byte[] arrBuffer = Base64.decode(source.substring(nPosComma + 1), Base64.DEFAULT); //byte[] arrBuffer = Base64Coder.decode(source.substring(nPosComma + 1)); Bitmap dBitmap = BitmapFactory.decodeByteArray(arrBuffer, 0, arrBuffer.length); d = new BitmapDrawable(dBitmap); d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight()); } } else { // url try { InputStream is = (InputStream) new URL(source).getContent(); Bitmap dBitmap = BitmapFactory.decodeStream(is); if (dBitmap == null) { d = Resources.getSystem().getDrawable(android.R.drawable.picture_frame); } else { d = new BitmapDrawable(dBitmap); d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight()); } d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /* URLDrawable urlDrawable = new URLDrawable(); // get the actual source ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask( urlDrawable); asyncTask.execute(source); // return reference to URLDrawable where I will change with actual image from // the src tag return urlDrawable; */ } return d; }
From source file:com.andernity.launcher2.InstallShortcutReceiver.java
private static void addToInstallQueue(SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) { synchronized (sLock) { try {/*from ww w .ja v a2 s . co m*/ JSONStringer json = new JSONStringer().object().key(DATA_INTENT_KEY).value(info.data.toUri(0)) .key(LAUNCH_INTENT_KEY).value(info.launchIntent.toUri(0)).key(NAME_KEY).value(info.name); if (info.icon != null) { byte[] iconByteArray = ItemInfo.flattenBitmap(info.icon); json = json.key(ICON_KEY) .value(Base64.encodeToString(iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); } if (info.iconResource != null) { json = json.key(ICON_RESOURCE_NAME_KEY).value(info.iconResource.resourceName); json = json.key(ICON_RESOURCE_PACKAGE_NAME_KEY).value(info.iconResource.packageName); } json = json.endObject(); SharedPreferences.Editor editor = sharedPrefs.edit(); addToStringSet(sharedPrefs, editor, APPS_PENDING_INSTALL, json.toString()); editor.commit(); } catch (org.json.JSONException e) { Log.d("InstallShortcutReceiver", "Exception when adding shortcut: " + e); } } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java
public static JSONObject json(byte[] data) { String encoded = Base64.encodeToString(data, Base64.DEFAULT); JSONObject obj = new JSONObject(); try {//from w ww .ja v a 2 s. c om obj.put("data", encoded); } catch (JSONException e) { } return obj; }
From source file:com.paymaya.sdk.android.payment.PayMayaPayment.java
/** * Request and returns a payment token//from w w w . j a va 2 s.com * * @return PaymentToken * @throws PayMayaPaymentException */ public PaymentToken getPaymentToken() throws PayMayaPaymentException { try { Request request = new Request(Request.Method.POST, PayMayaConfig.getEnvironment() == PayMayaConfig.ENVIRONMENT_PRODUCTION ? BuildConfig.API_PAYMENTS_ENDPOINT_PRODUCTION : BuildConfig.API_PAYMENTS_ENDPOINT_SANDBOX + "/payment-tokens"); byte[] body = JSONUtils.toJSON(mCard).toString().getBytes(); request.setBody(body); String key = mClientKey + ":"; String authorization = Base64.encodeToString(key.getBytes(), Base64.DEFAULT); Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", "application/json"); headers.put("Authorization", "Basic " + authorization); headers.put("Content-Length", Integer.toString(body.length)); headers.put("Idempotent-Token", mUuidIdempotentKey); request.setHeaders(headers); AndroidClient androidClient = new AndroidClient(); Response response = androidClient.call(request); //check errors return JSONUtils.fromJSONPaymentToken(response.getResponse()); } catch (JSONException je) { throw new PayMayaPaymentException("Unknown Error", je); } catch (PayMayaPaymentException ppe) { throw new PayMayaPaymentException(ppe.getMessage()); } }