Example usage for android.util Base64 DEFAULT

List of usage examples for android.util Base64 DEFAULT

Introduction

In this page you can find the example usage for android.util Base64 DEFAULT.

Prototype

int DEFAULT

To view the source code for android.util Base64 DEFAULT.

Click Source Link

Document

Default values for encoder/decoder flags.

Usage

From source file:Main.java

public static String bitmapToBase64(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 encodeBase64File(String path) throws Exception {
    File file = new File(path);
    FileInputStream inputFile = new FileInputStream(file);
    byte[] buffer = new byte[(int) file.length()];
    inputFile.read(buffer);// w ww  .j a  va2 s.c  o  m
    inputFile.close();
    return android.util.Base64.encodeToString(buffer, 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/*  w w w  .ja  v a2  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 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 base64EncodingSenhaLogin(String user, String password) {

    String param = user + ":" + password;

    byte[] data = null;
    try {// w ww . ja  va  2  s .c  o  m
        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 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  . ja va2  s.c  o  m*/
        } else {
            bytes[i] -= 1;
        }
    }
    return Base64.encodeToString(bytes, 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

/**
 * function encrypt the string and return the result
 * @param stringToEncrypt the string against which the encryption to be performed
 * @return the encrypted String/*from w w w.  ja  v  a2  s  . c  o  m*/
 */
public static final String encrypt(String stringToEncrypt) {
    try {
        byte[] data = stringToEncrypt.getBytes("UTF-8");
        String base64 = Base64.encodeToString(data, Base64.DEFAULT);
        return base64;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return stringToEncrypt;

    //        try {
    //            Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
    //            Cipher cipher = Cipher.getInstance("AES");
    //            cipher.init(Cipher.ENCRYPT_MODE, aesKey);
    //            byte[] encrypted = cipher.doFinal(stringToEncrypt.getBytes());
    //            return new String(encrypted);
    //        }catch (Exception e){
    //
    //        }
    //        return null;
}

From source file:Main.java

public static String encodeToBase64(Bitmap image) {
    Bitmap immagex = image;/*from  w  ww . j  av  a2s .  c om*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
    return imageEncoded;
}