private static String base64Encode(final byte[] input) { return Base64.encodeToString(input, Base64.DEFAULT); }
/** * @return the data. */ public String getDataBase64() { return Base64.encodeToString(data, Base64.DEFAULT); }
@Override public String encodeToString(byte[] input, int offset, int len) { return Base64.encodeToString(input, offset, len, BASE64_ENCODER_FLAGS); }
String encodeBase64(byte[] bytes) { return Base64.encodeToString(bytes, Base64.DEFAULT); }
@Override public String encode(String string) { try { return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 not supported", e); } }
private static String generateServerKey(String clientKey) { try { String serverKey = clientKey + SERVER_KEY_GUID; MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); sha1.update(Utf8Charset.encodeUTF8(serverKey)); return Base64.encodeToString(sha1.digest(), Base64.NO_WRAP); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
@Nullable public static String serialize(@NonNull Serializable serializable) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ObjectOutputStream outputStream = new ObjectOutputStream(out)) { outputStream.writeObject(serializable); return Base64.encodeToString(out.toByteArray(), Base64.DEFAULT); } catch (IOException e) { e.printStackTrace(); } return null; }
public static void writeByteArrayAttribute(XmlSerializer out, String name, byte[] value) throws IOException { if (value != null) { out.attribute(null, name, Base64.encodeToString(value, Base64.DEFAULT)); } }
@Override public String call() { View view = this.rootView.get(); if (view == null || view.getWidth() == 0 || view.getHeight() == 0) { return ""; } Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); view.draw(canvas); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // TODO: T25009391, Support better screenshot image quality by using file attachment. bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream); return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP); } }
@Override public String encrypt(String key, String plainText) throws Exception { Entity entity = Entity.create(key); byte[] bytes = crypto.encrypt(plainText.getBytes(), entity); return Base64.encodeToString(bytes, Base64.NO_WRAP); }
@JavascriptInterface public String getChunk(long begin, long end) { try { if (mRandomAccessFile == null) { mRandomAccessFile = new RandomAccessFile(mFile, "r"); } if (mRandomAccessFile != null) { final int bufferSize = (int)(end - begin); byte[] data = new byte[bufferSize]; mRandomAccessFile.seek(begin); mRandomAccessFile.read(data); return Base64.encodeToString(data, Base64.DEFAULT); } else { return ""; } } catch (IOException e) { Log.e("Exception", e.toString()); return ""; } }
/** * Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon * and base64 encodes them. This is useful for passing the telemetry to Google's backend * services. * @param beacon * @return base64 encoded telemetry bytes */ @TargetApi(Build.VERSION_CODES.FROYO) public String getBase64EncodedTelemetry(Beacon beacon) { byte[] bytes = getTelemetryBytes(beacon); if (bytes != null) { String base64EncodedTelemetry = Base64.encodeToString(bytes, Base64.DEFAULT); // 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Rehydrated telemetry bytes are :20 00 00 00 88 29 18 4d 00 00 18 4d 00 00 // 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Base64 telemetry bytes are :IAAAAIgpGE0AABhNAAA= Log.d(TAG, "Base64 telemetry bytes are :"+base64EncodedTelemetry); return base64EncodedTelemetry; } else { return null; } }
/** * Sets the HTTP Basic Authentication header. * @param username HTTP Basic Auth username * @param password HTTP Basic Auth password * @return self instance */ public B setBasicAuth(final String username, final String password) { String auth = Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP); httpParams.addHeader("Authorization", "Basic " + auth); return self(); }
@SuppressWarnings("deprecation") private String getBase64BitmapBytes(CompressFormat format) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Drawable drawable = Preconditions.checkNotNull(ContextCompat.getDrawable(context, ResourceIds.raw.canonical)); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); bitmap.compress(format, 100, bos); byte[] data = bos.toByteArray(); return Base64.encodeToString(data, /*flags=*/ 0); } }
/** * Base64-encode the given data and return a newly allocated String with the result. * * @param context * @param type * @return */ public static String Base64encoding(byte[] context, int type) { String result = ""; if (getSdkVersion() > 7) { result = Base64.encodeToString(context, type); } else { result = com.marshalchen.ua.common.commonUtils.urlUtils.Base64.encodeBytes(context); } return result; }
/** * Encrypt and encode message using 256-bit AES with key generated from password. * * * @param password used to generated key * @param message the thing you want to encrypt assumed String UTF-8 * @return Base64 encoded CipherText * @throws GeneralSecurityException if problems occur during encryption */ public static String encrypt(final String password, String message) throws GeneralSecurityException { try { final SecretKeySpec key = generateKey(password); log("message", message); byte[] cipherText = encrypt(key, ivBytes, message.getBytes(CHARSET)); //NO_WRAP is important as was getting \n at the end String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP); log("Base64.NO_WRAP", encoded); return encoded; } catch (UnsupportedEncodingException e) { if (DEBUG_LOG_ENABLED) Log.e(TAG, "UnsupportedEncodingException ", e); throw new GeneralSecurityException(e); } }
public void disabledTestSetClipboard() { // Cannot run this as a unit test since Base64 is a android.util class. enterString("\033]52;c;" + Base64.encodeToString("Hello, world".getBytes(), 0) + "\007"); }
@Override public long replace(CacheEntity cacheEntity) { SQLiteDatabase database = getWriter(); database.beginTransaction(); try { ContentValues values = new ContentValues(); values.put(CacheSQLHelper.KEY, cacheEntity.getKey()); values.put(CacheSQLHelper.HEAD, encrypt(cacheEntity.getResponseHeadersJson())); values.put(CacheSQLHelper.DATA, encrypt(Base64.encodeToString(cacheEntity.getData(), Base64.DEFAULT))); values.put(CacheSQLHelper.LOCAL_EXPIRES, encrypt(Long.toString(cacheEntity.getLocalExpire()))); long result = database.replace(getTableName(), null, values); database.setTransactionSuccessful(); return result; } catch (Exception e) { return -1; } finally { database.endTransaction(); closeDateBase(database); } }
private static String encodeUserInfo(UserInfo userInfo) { Parcel parcel = Parcel.obtain(); parcel.writeValue(userInfo); byte[] data = parcel.marshall(); parcel.recycle(); return Base64.encodeToString(data, Base64.DEFAULT); } }
@Test public void testPdfAndroidJavascriptBridgeGetChunk() throws IOException { final String path = this.getClass().getClassLoader().getResource("file.txt").getPath(); final File file = new File(path); final long size = file.length(); final String expected = Base64.encodeToString(Okio.buffer(Okio.source(file)).readByteArray(), Base64.DEFAULT); final WebFragment.PdfAndroidJavascriptBridge bridge = new WebFragment.PdfAndroidJavascriptBridge(path, null); assertEquals(expected, bridge.getChunk(0, size)); }