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:com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.JSONRecordAdapter.java

/**
 * returns data from json object which was made via translateFromRecord.
 *
 * @param jsonObject the json./* w  ww  .  j  av  a 2 s  .  co  m*/
 * @throws JSONException
 */
public static ByteBuffer getData(JSONObject jsonObject) throws JSONException {
    return ByteBuffer.wrap(Base64.decode(jsonObject.getString(DATA_FIELD_KEY), Base64.DEFAULT));
}

From source file:Main.java

public static String encryption(String string) throws Exception {
    // TODO Auto-generated method stub

    //generate symmetric key
    KeyGenerator keygt = KeyGenerator.getInstance("AES");
    keygt.init(128);/*from  w  w w.j a v a  2 s  .co m*/
    SecretKey symkey = keygt.generateKey();

    //get it encoded
    byte[] aes_ba = symkey.getEncoded();

    //create cipher
    SecretKeySpec skeySpec = new SecretKeySpec(aes_ba, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

    //encryption
    byte[] EncSymbyteArray = cipher.doFinal(string.getBytes());

    //encrypt symKey with PublicKey
    //        Key pubKey = getPublicKey();

    Key pubKey = publicKey;

    //RSA cipher
    Cipher cipherAsm = Cipher.getInstance("RSA", "BC");
    cipherAsm.init(Cipher.ENCRYPT_MODE, pubKey);

    //RSA encryption
    byte[] asymEncsymKey = cipherAsm.doFinal(aes_ba);

    //           File f3 = new File(BASE_PATH,"enc.txt");
    //           File f3key = new File(BASE_PATH,"enckey.txt");
    //           File f3file = new File(BASE_PATH,"encfile.txt");
    //           writeToFile2(f3,f3key,f3file, asymEncsymKey, EncSymbyteArray);

    //byte != new String
    //return new String(byteMerger(asymEncsymKey, EncSymbyteArray));
    return Base64.encodeToString(byteMerger(asymEncsymKey, EncSymbyteArray), Base64.DEFAULT);

}

From source file:bencoding.securely.Converters.java

public static Object deserializeObjectFromString(String objectString) throws Exception {

    ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(
            Base64.decode(objectString, Base64.DEFAULT));
    GZIPInputStream gzipInputStream = new GZIPInputStream(arrayInputStream);
    ObjectInputStream objectInputStream = new ObjectInputStream(gzipInputStream);

    Object object = objectInputStream.readObject();

    objectInputStream.close();/*from   w w  w.  j  a va 2s.c  o  m*/
    gzipInputStream.close();
    arrayInputStream.close();

    return object;
}

From source file:illab.nabal.util.SecurityHelper.java

/**
  * AES-encrypt a plain message. Return null if message is empty.
  * // w ww. j  a v a 2 s.  c o  m
  * @param message
  * @return AES encrypted hex
  * @throws Exception
  */
public static String cipher(String message) throws Exception {
    if (StringHelper.isEmpty(message) == false) {
        Cipher cipher = Cipher.getInstance(AES);
        cipher.init(Cipher.ENCRYPT_MODE, SYSTEM_SECRET_KEY_SPEC);
        return Base64.encodeToString(cipher.doFinal(message.getBytes()), Base64.DEFAULT);
    } else {
        return null;
    }
}

From source file:com.orange.oidc.secproxy_service.Token.java

static String getJSON(String token) {
    String ds = null;//from   w  w  w . j  a va2s . com

    String tokenB64 = null;
    if (token != null) {
        String[] p = token.split("\\.");
        if (p != null && p.length == 3) {
            tokenB64 = p[1];
        }
    }

    if (tokenB64 != null) {
        byte[] decoded = null;
        try {
            decoded = Base64.decode(tokenB64, Base64.URL_SAFE);
            ds = new String(decoded, "UTF-8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (decoded == null) {
            try {
                decoded = Base64.decode(tokenB64, Base64.DEFAULT);
                ds = new String(decoded, "UTF-8");
            } catch (Exception ee) {
                // TODO Auto-generated catch block
                ee.printStackTrace();
            }
        }
    }
    return ds;
}

From source file:Main.java

/**
 * Returns the key hashes of the signatures of the app with the specified package name
 * which may be needed when integrating with 3rd party services such as Facebook. Note that
 * Android apps usually only have one signature.
 *
 * @param context/*from  w w  w  . j av a  2 s .  co m*/
 * @param packageName The package name of the app
 * @return The key hashes
 */
public static List<String> getKeyHashes(Context context, String packageName) {
    try {
        List<String> hashes = new ArrayList<>();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            hashes.add(Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
        return hashes;
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    return null;
}

From source file:illab.nabal.util.SecurityHelper.java

/**
 * Decrypt a AES-encrypted message./*from   w w w. j  a v a2 s  . c  o  m*/
 * 
 * @param encrypted
 * @return String
 * @throws Exception
 */
public static String decipher(String encrypted) throws Exception {
    if (StringHelper.isEmpty(encrypted) == false) {
        Cipher cipher = Cipher.getInstance(AES);
        cipher.init(Cipher.DECRYPT_MODE, SYSTEM_SECRET_KEY_SPEC);
        return new String(cipher.doFinal(Base64.decode(encrypted, Base64.DEFAULT)), HTTP.UTF_8);
    } else {
        return null;
    }
}

From source file:com.phonegap.plugins.xapkreader.XAPKReader.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("get")) {
        final String filename = args.getString(0);
        try {/*from www.  j av a  2 s .c o m*/
            Context ctx = cordova.getActivity().getApplicationContext();
            // Read file as array buffer
            byte[] data = XAPKReader.readFile(ctx, filename);
            if (null != data) {
                // Encode to Base64 string
                String encoded = Base64.encodeToString(data, Base64.DEFAULT);
                // Return file data as base64 string
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, encoded));
            } else {
                callbackContext.error("File not found.");
            }
        } catch (Exception e) {
            e.printStackTrace();
            callbackContext.error(e.getMessage());
        }
        return true;
    }
    return false;
}

From source file:com.royclarkson.springagram.model.ItemResource.java

public void setImage(String imageDataUri) {
    String imageDataString = imageDataUri.substring(imageDataUri.indexOf(",") + 1);
    byte[] imageData = Base64.decode(imageDataString, Base64.DEFAULT);
    Bitmap original = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
    this.image = ThumbnailUtils.extractThumbnail(original, IMAGE_WIDTH, IMAGE_HEIGHT);
    this.thumbnail = ThumbnailUtils.extractThumbnail(original, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
}

From source file:com.drisoftie.cwdroid.util.CredentialUtils.java

public static String obfuscateToBase64(byte[] key, String pure) {
    String result = null;//from  ww w.j  a  v a 2s. co  m
    try {
        byte[] encrypted = encrypt(key, pure.getBytes());
        result = Base64.encodeToString(encrypted, Base64.DEFAULT);
    } catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException
            | IllegalBlockSizeException e) {
        e.printStackTrace();
    }
    return result;
}