List of usage examples for android.util Base64 encodeToString
public static String encodeToString(byte[] input, int flags)
From source file:Main.java
/** * A reusable method to make our simple XOR hiding method. Since the interesting part is * how we get the hiding key, we've moved everything else into this reusable method. * * @param msg The message to hide/unhide * @param pwd Our password key to use in the XOR process * @param isHidden whether we're encrypting or unencrypting (relevant only for logging) *//* ww w . ja va 2 s . c o m*/ public static void doHiding(byte[] msg, byte[] pwd, boolean isHidden) { xorValues(msg, pwd); if (!isHidden) { String hiddenMessage = Base64.encodeToString(msg, 0); Log.i(TAG, String.format("Hidden Message: %s", hiddenMessage)); doHiding(msg, pwd, true); } else { Log.i(TAG, String.format("Unhidden Message: %s", new String(msg))); } }
From source file:Main.java
public static String doSignWithSHA1(String toSign, String keyString) throws Exception { SecretKeySpec key = new SecretKeySpec((keyString).getBytes(UTF_8), HMAC_SHA1); Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key);//from w w w. ja v a2 s . c o m byte[] bytes = mac.doFinal(toSign.getBytes(UTF_8)); return Base64.encodeToString(bytes, Base64.CRLF).replace(CARRIAGE_RETURN, EMPTY_STRING); }
From source file:Main.java
public static String getBasicAuthHeaderValue(String username, String password) { return "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP); }
From source file:Main.java
public static String getAuthorizationString() { String authorizationString = "Basic " + Base64.encodeToString( (PRINT_METRICS_USER_NAME + ":" + PRINT_METRICS_PASSWORD).getBytes(), Base64.NO_WRAP); return authorizationString; }
From source file:Main.java
public static void printHashKey(Context context) { try {/*from w ww. ja v a 2 s . c o m*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (android.content.pm.Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.e("HASH KEY:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:Main.java
public static String base64Encode(String str) { return Base64.encodeToString(str.getBytes(), Base64.DEFAULT); }
From source file:Main.java
static String encodeB64(byte[] bytes) { try {// www. j a v a 2 s . c om return Base64.encodeToString(bytes, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP); } catch (Exception e) { } return null; }
From source file:Main.java
/** * Create a temporary filename to store the result of a download. * // w ww .j a va 2s. co m * @param url Name of the URL. * @return String containing the temporary filename. */ static private String getTemporaryFilename(final String url) { // This is what you'd normally call to get a unique temporary // filename, but for testing purposes we always name the file // the same to avoid filling up student phones with numerous // files! // // return Base64.encodeToString(url.getBytes(), // Base64.NO_WRAP) // + System.currentTimeMillis()); return Base64.encodeToString(url.getBytes(), Base64.NO_WRAP); }
From source file:Main.java
/** * Compresses a bitmap into a PNG and converts into a Base64 encoded string. * The encoded string can be decoded using {@link decodeBitmapFromString(String)}. * @param bitmap The Bitmap to compress and encode. * @return the String encoding the Bitmap. */// ww w.ja va 2 s . c o m public static String encodeBitmapAsString(Bitmap bitmap) { if (bitmap == null) return ""; ByteArrayOutputStream output = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); }
From source file:Main.java
public static void printOutMyHashKey(Context context, String packageName) { try {//from ww w . j ava 2 s . co m PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }