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:Main.java
public static void printOutMyHashKey(Context context, String packageName) { try {//ww w . jav a 2 s . com 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(); } }
From source file:Main.java
public static String decodeBase64(String s) { return new String(Base64.decode(s, Base64.DEFAULT)); }
From source file:Main.java
public static String getHashKey(Context context) { // Add code to print out the key hash try {// w w w . j a v a 2 s . c o m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); return Base64.encodeToString(md.digest(), Base64.DEFAULT); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return null; }
From source file:Main.java
/** * Return a byte[] containing the bytes in a given base64 string, or null if this is not a valid * base64 string.// w w w. jav a 2s . co m */ public static byte[] getBytesFromBase64(String base64) { try { return Base64.decode(base64, Base64.DEFAULT); } catch (Exception e) { Log.e(LOGTAG, "exception decoding bitmap from data URI: " + base64, e); } return null; }
From source file:Main.java
public static String encodeBase64(String s) { return Base64.encodeToString(s.getBytes(), Base64.DEFAULT); }
From source file:Main.java
public static String keyHash(Context context) { String key = ""; try {/*from w w w. j av a 2 s .c o m*/ PackageInfo info = context.getPackageManager().getPackageInfo("org.tathva.triloaded.anubhava", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); key = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d("anas", key); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return key; }
From source file:Main.java
public static byte[] readByteArrayAttribute(XmlPullParser in, String name) { final String value = in.getAttributeValue(null, name); if (value != null) { return Base64.decode(value, Base64.DEFAULT); } else {/*from w ww. ja v a2s . co m*/ return null; } }
From source file:Main.java
public static void writeByteArrayAttribute(XmlSerializer out, String name, byte[] value) throws IOException { if (value != null) { out.attribute(null, name, Base64.encodeToString(value, Base64.DEFAULT)); }/*ww w . j a v a 2s . c o m*/ }
From source file:Main.java
/** * Print hash key/*from w w w.j av a 2s.c om*/ */ public static void printHashKey(Context context) { try { PackageInfo info = context.getPackageManager().getPackageInfo(TAG, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d(TAG, "keyHash: " + keyHash); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:Main.java
public static String toString(X509Certificate certificate) throws CertificateEncodingException { String header = "-----BEGIN CERTIFICATE-----\n"; String cert = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); String footer = "-----END CERTIFICATE-----"; return header + cert + footer; }