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.ruesga.rview.fragments.EditorFragment.java
private byte[] readEditContent(String file) throws IOException { byte[] o = CacheHelper.readAccountDiffCacheFile(getContext(), getEditCachedFileName(file)); if (o == null || o.length == 0) { return new byte[0]; }/* w ww. j av a 2 s. c om*/ return Base64.decode(o, Base64.NO_WRAP); }
From source file:net.openid.appauth.AuthorizationRequest.java
private static String generateRandomState() { SecureRandom sr = new SecureRandom(); byte[] random = new byte[STATE_LENGTH]; sr.nextBytes(random);//from www. j a va 2s . c o m return Base64.encodeToString(random, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE); }
From source file:self.philbrown.droidQuery.AjaxOptions.java
/** * As a security feature, this class will not allow queries of authentication passwords. This * method will instead encode the security credentials (username and password) using * Base64-encryption, and return the encrypted data as a byte array. * @return the encrypted credentials/*from w w w.java 2 s. com*/ * @see #username() * @see #password(String) */ public byte[] getEncodedCredentials() { StringBuilder auth = new StringBuilder(); if (username != null) { auth.append(username); } if (password != null) { auth.append(":").append(password); } return Base64.encode(auth.toString().getBytes(), Base64.NO_WRAP); }
From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java
/** * @param docRevisionJSON - The JSONObject to transform * @return - The DocumentRevision from the converted JSONObject * @throws Exception//from w w w . ja v a 2 s .com */ private DocumentRevision buildDocRevision(JSONObject docRevisionJSON) throws Exception { if (docRevisionJSON == null) throw new Exception("Document revision cannot be null"); String docId = null; String docRev = null; DocumentBody body; if (docRevisionJSON.has(DOC_ID)) { docId = (String) docRevisionJSON.get(DOC_ID); } if (docRevisionJSON.has(DOC_REV)) { docRev = (String) docRevisionJSON.get(DOC_REV); } DocumentRevision revision = new DocumentRevision(docId, docRev); if (docRevisionJSON.has(DOC_DELETED) && docRevisionJSON.getBoolean(DOC_DELETED)) { revision.setDeleted(); } Map<String, Attachment> attachmentMap = null; if (docRevisionJSON.has(DOC_ATTACHMENTS)) { JSONObject attachments = docRevisionJSON.getJSONObject(DOC_ATTACHMENTS); docRevisionJSON.remove(DOC_ATTACHMENTS); attachmentMap = new HashMap<String, Attachment>(); Iterator<String> keys = attachments.keys(); while (keys.hasNext()) { String name = keys.next(); JSONObject attachment = attachments.getJSONObject(name); String contentType = attachment.getString(DOC_ATTACHMENTS_CONTENT_TYPE); String data = attachment.getString("data"); byte[] bytes = Base64.decode(data, Base64.NO_WRAP); UnsavedStreamAttachment streamAttachment = new UnsavedStreamAttachment( new ByteArrayInputStream(bytes), contentType); attachmentMap.put(name, streamAttachment); } revision.setAttachments(attachmentMap); } revision.setBody(DocumentBodyFactory.create(getMapFromJSONObject(docRevisionJSON))); return revision; }
From source file:org.deviceconnect.android.localoauth.LocalOAuth2Main.java
/** * ??????.//from w w w .j a v a 2 s . c om * * @param client * @param authCode ??(TokenManager.sessions???) * @param applicationName ?? * @return not null: / null: ? */ private String callAccessTokenServerResource(final Client client, final String authCode, final String applicationName) { Request request = new Request(); ClientInfo clientInfo = new ClientInfo(); org.restlet.security.User user = new org.restlet.security.User(client.getClientId()); clientInfo.setUser(user); request.setClientInfo(clientInfo); Response response = new Response(request); AccessTokenServerResource.init(request, response); // (???base64?) String base64ApplicationName = Base64.encodeToString(applicationName.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP); StringRepresentation input = new StringRepresentation("grant_type=authorization_code&code=" + authCode + "&" + AccessTokenServerResource.REDIR_URI + "=" + DUMMY_REDIRECT_URI + "&" + AccessTokenServerResource.APPLICATION_NAME + "=" + base64ApplicationName); try { ResultRepresentation resultRepresentation = (ResultRepresentation) AccessTokenServerResource .requestToken(input); if (resultRepresentation.getResult()) { return resultRepresentation.getText(); } } catch (JSONException | OAuthException e) { e.printStackTrace(); } return null; }
From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java
/** * @param rev - The DocumentRevision to transform * @return - The JSONObject from the converted DocumentRevision * @throws JSONException/*from w w w . j a v a 2 s.co m*/ * @throws IOException */ private JSONObject buildJSON(DocumentRevision rev, boolean isCreate) throws JSONException, IOException { JSONObject result = new JSONObject(); result.put(DOC_ID, rev.getId()); result.put(DOC_REV, rev.getRevision()); if (!isCreate) { result.put(DOC_DELETED, rev.isDeleted()); } if (!rev.isDeleted()) { Map<String, Attachment> attachmentMap = rev.getAttachments(); if (attachmentMap != null && !attachmentMap.isEmpty()) { JSONObject attachments = new JSONObject(); for (Map.Entry<String, Attachment> entry : attachmentMap.entrySet()) { Attachment attachment = entry.getValue(); InputStream is = attachment.getInputStream(); byte[] bytes = IOUtils.toByteArray(is); String data = Base64.encodeToString(bytes, Base64.NO_WRAP); JSONObject attachmentJSON = new JSONObject(); attachmentJSON.put(DOC_ATTACHMENTS_CONTENT_TYPE, attachment.type); attachmentJSON.put(DOC_ATTACHMENTS_DATA, data); attachments.put(entry.getKey(), attachmentJSON); } result.put(DOC_ATTACHMENTS, attachments); } } Map<String, Object> body = rev.getBody().asMap(); for (Map.Entry<String, Object> entry : body.entrySet()) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:org.telegram.ui.PassportActivity.java
public PassportActivity(int type, int botId, String scope, String publicKey, String payload, String nonce, String callbackUrl, TLRPC.TL_account_authorizationForm form, TLRPC.TL_account_password accountPassword) { this(type, form, accountPassword, null, null, null, null, null, null); currentBotId = botId;//from w ww . jav a 2 s. co m currentPayload = payload; currentNonce = nonce; currentScope = scope; currentPublicKey = publicKey; currentCallbackUrl = callbackUrl; if (type == TYPE_REQUEST) { if (!form.errors.isEmpty()) { try { Collections.sort(form.errors, new Comparator<TLRPC.SecureValueError>() { int getErrorValue(TLRPC.SecureValueError error) { if (error instanceof TLRPC.TL_secureValueError) { return 0; } else if (error instanceof TLRPC.TL_secureValueErrorFrontSide) { return 1; } else if (error instanceof TLRPC.TL_secureValueErrorReverseSide) { return 2; } else if (error instanceof TLRPC.TL_secureValueErrorSelfie) { return 3; } else if (error instanceof TLRPC.TL_secureValueErrorTranslationFile) { return 4; } else if (error instanceof TLRPC.TL_secureValueErrorTranslationFiles) { return 5; } else if (error instanceof TLRPC.TL_secureValueErrorFile) { return 6; } else if (error instanceof TLRPC.TL_secureValueErrorFiles) { return 7; } else if (error instanceof TLRPC.TL_secureValueErrorData) { TLRPC.TL_secureValueErrorData errorData = (TLRPC.TL_secureValueErrorData) error; return getFieldCost(errorData.field); } return 100; } @Override public int compare(TLRPC.SecureValueError e1, TLRPC.SecureValueError e2) { int val1 = getErrorValue(e1); int val2 = getErrorValue(e2); if (val1 < val2) { return -1; } else if (val1 > val2) { return 1; } return 0; } }); for (int a = 0, size = form.errors.size(); a < size; a++) { TLRPC.SecureValueError secureValueError = form.errors.get(a); String key; String description; String target; String field = null; byte[] file_hash = null; if (secureValueError instanceof TLRPC.TL_secureValueErrorFrontSide) { TLRPC.TL_secureValueErrorFrontSide secureValueErrorFrontSide = (TLRPC.TL_secureValueErrorFrontSide) secureValueError; key = getNameForType(secureValueErrorFrontSide.type); description = secureValueErrorFrontSide.text; file_hash = secureValueErrorFrontSide.file_hash; target = "front"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorReverseSide) { TLRPC.TL_secureValueErrorReverseSide secureValueErrorReverseSide = (TLRPC.TL_secureValueErrorReverseSide) secureValueError; key = getNameForType(secureValueErrorReverseSide.type); description = secureValueErrorReverseSide.text; file_hash = secureValueErrorReverseSide.file_hash; target = "reverse"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorSelfie) { TLRPC.TL_secureValueErrorSelfie secureValueErrorSelfie = (TLRPC.TL_secureValueErrorSelfie) secureValueError; key = getNameForType(secureValueErrorSelfie.type); description = secureValueErrorSelfie.text; file_hash = secureValueErrorSelfie.file_hash; target = "selfie"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorTranslationFile) { TLRPC.TL_secureValueErrorTranslationFile secureValueErrorTranslationFile = (TLRPC.TL_secureValueErrorTranslationFile) secureValueError; key = getNameForType(secureValueErrorTranslationFile.type); description = secureValueErrorTranslationFile.text; file_hash = secureValueErrorTranslationFile.file_hash; target = "translation"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorTranslationFiles) { TLRPC.TL_secureValueErrorTranslationFiles secureValueErrorTranslationFiles = (TLRPC.TL_secureValueErrorTranslationFiles) secureValueError; key = getNameForType(secureValueErrorTranslationFiles.type); description = secureValueErrorTranslationFiles.text; target = "translation"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorFile) { TLRPC.TL_secureValueErrorFile secureValueErrorFile = (TLRPC.TL_secureValueErrorFile) secureValueError; key = getNameForType(secureValueErrorFile.type); description = secureValueErrorFile.text; file_hash = secureValueErrorFile.file_hash; target = "files"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorFiles) { TLRPC.TL_secureValueErrorFiles secureValueErrorFiles = (TLRPC.TL_secureValueErrorFiles) secureValueError; key = getNameForType(secureValueErrorFiles.type); description = secureValueErrorFiles.text; target = "files"; } else if (secureValueError instanceof TLRPC.TL_secureValueError) { TLRPC.TL_secureValueError secureValueErrorAll = (TLRPC.TL_secureValueError) secureValueError; key = getNameForType(secureValueErrorAll.type); description = secureValueErrorAll.text; file_hash = secureValueErrorAll.hash; target = "error_all"; } else if (secureValueError instanceof TLRPC.TL_secureValueErrorData) { TLRPC.TL_secureValueErrorData secureValueErrorData = (TLRPC.TL_secureValueErrorData) secureValueError; boolean found = false; for (int b = 0; b < form.values.size(); b++) { TLRPC.TL_secureValue value = form.values.get(b); if (value.data != null && Arrays.equals(value.data.data_hash, secureValueErrorData.data_hash)) { found = true; break; } } if (!found) { continue; } key = getNameForType(secureValueErrorData.type); description = secureValueErrorData.text; field = secureValueErrorData.field; file_hash = secureValueErrorData.data_hash; target = "data"; } else { continue; } HashMap<String, String> vals = errorsMap.get(key); if (vals == null) { vals = new HashMap<>(); errorsMap.put(key, vals); mainErrorsMap.put(key, description); } String hash; if (file_hash != null) { hash = Base64.encodeToString(file_hash, Base64.NO_WRAP); } else { hash = ""; } if ("data".equals(target)) { if (field != null) { vals.put(field, description); } } else if ("files".equals(target)) { if (file_hash != null) { vals.put("files" + hash, description); } else { vals.put("files_all", description); } } else if ("selfie".equals(target)) { vals.put("selfie" + hash, description); } else if ("translation".equals(target)) { if (file_hash != null) { vals.put("translation" + hash, description); } else { vals.put("translation_all", description); } } else if ("front".equals(target)) { vals.put("front" + hash, description); } else if ("reverse".equals(target)) { vals.put("reverse" + hash, description); } else if ("error_all".equals(target)) { vals.put("error_all", description); } } } catch (Exception ignore) { } } } }
From source file:csh.cryptonite.Cryptonite.java
public static String encrypt(String value, Context context) throws RuntimeException { try {//from www . j ava 2s .c o m final byte[] bytes = value != null ? value.getBytes("utf-8") : new byte[0]; SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(jniFullPw().toCharArray())); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(Settings.Secure .getString(context.getContentResolver(), Settings.Secure.ANDROID_ID).getBytes("utf-8"), 20)); return new String(Base64.encode(pbeCipher.doFinal(bytes), Base64.NO_WRAP), "utf-8"); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.android.exchange.EasSyncService.java
/** * Using mUserName and mPassword, create and cache mAuthString and mCacheString, which are used * in all HttpPost commands. This should be called if these strings are null, or if mUserName * and/or mPassword are changed/*from w w w. jav a2 s .c o m*/ */ @SuppressWarnings("deprecation") private void cacheAuthAndCmdString() { String safeUserName = URLEncoder.encode(mUserName); String cs = mUserName + ':' + mPassword; mAuthString = "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP); mCmdString = "&User=" + safeUserName + "&DeviceId=" + mDeviceId + "&DeviceType=" + mDeviceType; }
From source file:com.remobile.file.FileUtils.java
/** * Read the contents of a file./*from www . j a va 2 s . c om*/ * This is done in a background thread; the result is sent to the callback. * * @param start Start position in the file. * @param end End position to stop at (exclusive). * @param callbackContext The context through which to send the result. * @param encoding The encoding to return contents as. Typical value is UTF-8. (see http://www.iana.org/assignments/character-sets) * @param resultType The desired type of data to send to the callback. * @return Contents of file. */ public void readFileAs(final String srcURLstr, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) throws MalformedURLException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } fs.readFileAtURL(inputURL, start, end, new Filesystem.ReadFileCallback() { public void handleData(InputStream inputStream, String contentType) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); final int BUFFER_SIZE = 8192; byte[] buffer = new byte[BUFFER_SIZE]; for (;;) { int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE); if (bytesRead <= 0) { break; } os.write(buffer, 0, bytesRead); } PluginResult result; switch (resultType) { case PluginResult.MESSAGE_TYPE_STRING: result = new PluginResult(PluginResult.Status.OK, os.toString(encoding)); break; case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: result = new PluginResult(PluginResult.Status.OK, os.toByteArray()); break; case PluginResult.MESSAGE_TYPE_BINARYSTRING: result = new PluginResult(PluginResult.Status.OK, os.toByteArray(), true); break; default: // Base64. byte[] base64 = Base64.encode(os.toByteArray(), Base64.NO_WRAP); String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII"); result = new PluginResult(PluginResult.Status.OK, s); } callbackContext.sendPluginResult(result); } catch (IOException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR)); } } }); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } catch (FileNotFoundException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_FOUND_ERR)); } catch (IOException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR)); } }