List of usage examples for android.util Base64 encodeToString
public static String encodeToString(byte[] input, int flags)
From source file:Main.java
public static String SHA256(String text) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(text.getBytes());/*from www . ja v a 2 s .c o m*/ byte[] digest = md.digest(); return Base64.encodeToString(digest, Base64.DEFAULT); }
From source file:Main.java
public static String serializeCert(X509Certificate cert) throws CertificateEncodingException { StringBuffer buffer = new StringBuffer(); buffer.append("-----BEGIN CERTIFICATE-----\n"); buffer.append(Base64.encodeToString(cert.getEncoded(), Base64.DEFAULT)); buffer.append("\n-----END CERTIFICATE-----"); return buffer.toString(); }
From source file:Main.java
public static String getBase64FromBitmap(Bitmap bitmap) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); return Base64.encodeToString(byteArray, Base64.DEFAULT); }
From source file:Main.java
public static String bitmapToString(Bitmap bitmap) { String bitmapString = null;/* w w w. j a v a 2 s. co m*/ ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bStream); byte[] bytes = bStream.toByteArray(); bitmapString = Base64.encodeToString(bytes, Base64.DEFAULT); return bitmapString; }
From source file:Main.java
/** * Encodes a string with Base64// ww w. j av a 2 s . c o m * * @param input String to be encoded * @return Base64 encoded input * @throws UnsupportedEncodingException */ public static String encodeBase64(String input) throws UnsupportedEncodingException { byte[] data = input.getBytes("UTF-8"); return Base64.encodeToString(data, Base64.DEFAULT); }
From source file:Main.java
public static String base64EncodingSenhaLogin(String user, String password) { String param = user + ":" + password; byte[] data = null; try {/*from w w w .j a v a 2s . c om*/ data = param.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return Base64.encodeToString(data, Base64.DEFAULT).trim(); }
From source file:Main.java
public static String bmpToStrBase64(Bitmap bitmap) { Bitmap bm = bitmap;/* w w w .ja va2 s .co m*/ ByteArrayOutputStream stream = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 80, stream); //bm is the bitmap object byte[] b = stream.toByteArray(); String strBase64 = Base64.encodeToString(b, 0); return strBase64; }
From source file:Main.java
public static String encryption(String pwd) throws UnsupportedEncodingException { byte[] bytes = pwd.getBytes("utf-8"); for (int i = 0; i < bytes.length; i++) { if (i % 2 == 0) { bytes[i] += 1;/*from ww w . jav a2s . c om*/ } else { bytes[i] -= 1; } } return Base64.encodeToString(bytes, Base64.DEFAULT); }
From source file:Main.java
public static String encodeToFile(File file) { try {//www. j a v a 2 s. c o m FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer); inputFile.close(); return Base64.encodeToString(buffer, Base64.NO_WRAP); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * convert (encode) image to string/*from w w w .j a va 2 s.com*/ * **/ public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality) { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); image.compress(compressFormat, quality, byteArrayOS); return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT); }