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:org.bcsphere.bluetooth.tools.Tools.java
public static String encodeBase64(byte[] value) { return Base64.encodeToString(value, Base64.NO_WRAP | Base64.NO_PADDING); }
From source file:de.tum.frm2.nicos_android.nicos.NicosClient.java
private PublicKey extractPublicKey(String source) { // Java wants the key formatted without prefix and postfix. String prefix = "-----BEGIN RSA PUBLIC KEY-----"; String postfix = "\n-----END RSA PUBLIC KEY-----"; // Java's string formatting/slicing is... 'slightly' inferior to python's. String keyNoPrefix = source.substring(prefix.length()); String reversed = new StringBuilder(keyNoPrefix).reverse().toString(); String reversedNoPostfix = reversed.substring(postfix.length()); String keyString = new StringBuilder(reversedNoPostfix).reverse().toString(); keyString = keyString.replace("\n", ""); ASN1InputStream in = new ASN1InputStream(Base64.decode(keyString, Base64.NO_WRAP)); ASN1Primitive obj;/*from w w w .j ava 2 s .c om*/ try { obj = in.readObject(); } catch (IOException e) { return null; } RSAPublicKey key = RSAPublicKey.getInstance(obj); RSAPublicKeySpec keySpec = null; if (key != null) { keySpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); } KeyFactory keyFactory = null; try { keyFactory = KeyFactory.getInstance("RSA"); } catch (NoSuchAlgorithmException e) { // Cannot happen. } PublicKey pubkey = null; try { if (keyFactory != null) { pubkey = keyFactory.generatePublic(keySpec); } } catch (InvalidKeySpecException e) { // Cannot (SHOULD NOT) happen. } return pubkey; }
From source file:com.ruesga.rview.fragments.EditorFragment.java
private void readFileContent(final OnSavedContentReady cb) { final String file = mFile; mBinding.editor.readContent(new EditorView.OnReadContentReadyListener() { @Override//from w w w. jav a 2 s. c om public void onReadContentReady(byte[] content) { if (content.length > 0) { String name = getEditCachedFileName(file); if (DEBUG) { Log.i(TAG, new String(Base64.decode(content, Base64.NO_WRAP))); } try { CacheHelper.writeAccountDiffCacheFile(getActivity(), name, content); mContentFile = new File(CacheHelper.getAccountDiffCacheDir(getActivity(), mAccount), name) .getAbsolutePath(); } catch (IOException ex) { Log.w(TAG, "Failed to store edit for " + file); } } if (cb != null) { cb.onContentSaved(); } } @Override public void onContentUnchanged() { if (cb != null) { cb.onContentSaved(); } } }); }
From source file:uk.bowdlerize.API.java
@Deprecated private String SignHeaders(String dataToSign, boolean isUser) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, NoSuchProviderException, SignatureException { PKCS8EncodedKeySpec spec;/*from w ww. j a v a 2 s. com*/ if (isUser) { spec = new PKCS8EncodedKeySpec( Base64.decode(settings.getString(SETTINGS_USER_PRIVATE_KEY, "").getBytes(), 0)); } else { spec = new PKCS8EncodedKeySpec( Base64.decode(settings.getString(SETTINGS_PROBE_PRIVATE_KEY, "").getBytes(), 0)); } KeyFactory kf = KeyFactory.getInstance("RSA", "BC"); PrivateKey pk = kf.generatePrivate(spec); byte[] signed = null; //Log.e("algorithm", pk.getAlgorithm()); Signature instance = Signature.getInstance("SHA1withRSA"); instance.initSign(pk); instance.update(dataToSign.getBytes()); signed = instance.sign(); Log.e("privateKey", settings.getString(SETTINGS_USER_PRIVATE_KEY, "")); Log.e("privateKey", settings.getString(SETTINGS_PROBE_PRIVATE_KEY, "")); //Log.e("Signature",Base64.encodeToString(signed, Base64.NO_WRAP)); return Base64.encodeToString(signed, Base64.NO_WRAP); }
From source file:uk.org.ngo.squeezer.service.SqueezeService.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private void downloadSong(@NonNull Uri url, String title, @NonNull Uri serverUrl) { if (url.equals(Uri.EMPTY)) { return;/*w w w . j av a 2 s . com*/ } // If running on Gingerbread or greater use the Download Manager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadDatabase downloadDatabase = new DownloadDatabase(this); String localPath = getLocalFile(serverUrl); String tempFile = UUID.randomUUID().toString(); String credentials = mUsername + ":" + mPassword; String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); DownloadManager.Request request = new DownloadManager.Request(url).setTitle(title) .setDestinationInExternalFilesDir(this, Environment.DIRECTORY_MUSIC, tempFile) .setVisibleInDownloadsUi(false) .addRequestHeader("Authorization", "Basic " + base64EncodedCredentials); long downloadId = downloadManager.enqueue(request); Crashlytics.log("Registering new download"); Crashlytics.log("downloadId: " + downloadId); Crashlytics.log("tempFile: " + tempFile); Crashlytics.log("localPath: " + localPath); if (!downloadDatabase.registerDownload(downloadId, tempFile, localPath)) { Crashlytics.log(Log.WARN, TAG, "Could not register download entry for: " + downloadId); downloadManager.remove(downloadId); } } }
From source file:com.connectsdk.service.WebOSTVService.java
private void sendToast(JSONObject payload, ResponseListener<Object> listener) { if (!payload.has("iconData")) { Context context = DiscoveryManager.getInstance().getContext(); try {/*w w w .j a va 2 s . c om*/ Drawable drawable = context.getPackageManager().getApplicationIcon(context.getPackageName()); if (drawable != null) { BitmapDrawable bitDw = ((BitmapDrawable) drawable); Bitmap bitmap = bitDw.getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] bitmapByte = stream.toByteArray(); bitmapByte = Base64.encode(bitmapByte, Base64.NO_WRAP); String bitmapData = new String(bitmapByte); payload.put("iconData", bitmapData); payload.put("iconExtension", "png"); } } catch (NameNotFoundException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } String uri = "palm://system.notifications/createToast"; ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, listener); request.send(); }
From source file:org.apache.cordova.FileUtils.java
/** * Read the contents of a file./*from ww w . ja v a 2s. c om*/ * This is done in a background thread; the result is sent to the callback. * * @param filename The name of the file. * @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 filename, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) { this.cordova.getThreadPool().execute(new Runnable() { public void run() { try { byte[] bytes = readAsBinaryHelper(filename, start, end); PluginResult result; switch (resultType) { case PluginResult.MESSAGE_TYPE_STRING: result = new PluginResult(PluginResult.Status.OK, new String(bytes, encoding)); break; case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: result = new PluginResult(PluginResult.Status.OK, bytes); break; case PluginResult.MESSAGE_TYPE_BINARYSTRING: result = new PluginResult(PluginResult.Status.OK, bytes, true); break; default: // Base64. String contentType = FileHelper.getMimeType(filename, cordova); byte[] base64 = Base64.encode(bytes, Base64.NO_WRAP); String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII"); result = new PluginResult(PluginResult.Status.OK, s); } callbackContext.sendPluginResult(result); } 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)); } } }); }
From source file:com.cordova.photo.CameraLauncher.java
/** * Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript. * * @param bitmap// w w w . j a v a2 s.c o m */ public void processPicture(Bitmap bitmap) { ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream(); try { if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) { byte[] code = jpeg_data.toByteArray(); byte[] output = Base64.encode(code, Base64.NO_WRAP); String js_out = new String(output); this.callbackContext.success(js_out); js_out = null; output = null; code = null; } } catch (Exception e) { this.failPicture("Error compressing image."); } jpeg_data = null; }
From source file:com.ruesga.rview.fragments.FileDiffViewerFragment.java
@SuppressWarnings("ConstantConditions") private File fetchCachedContent(String changeId, String revision, String base) { String b = base == null ? "0" : base; String name = b + "_" + mFileHash + "_" + CacheHelper.CACHE_CONTENT; File fetchedFile = new File(CacheHelper.getAccountDiffCacheDir(getContext()), name); if (!fetchedFile.exists()) { try {// ww w. j av a 2 s .c om final Context ctx = getActivity(); final GerritApi api = ModelHelper.getGerritApi(ctx); ResponseBody content = api.getChangeRevisionFileContent(changeId, revision, mFile).blockingFirst(); CacheHelper.writeAccountDiffCacheFile(getContext(), mAccount, name, Base64.decode(content.bytes(), Base64.NO_WRAP)); } catch (Exception ex) { Log.e(TAG, "Can't download file content " + mFile + "; Revision: " + revision, ex); fetchedFile = null; } } return fetchedFile; }