Example usage for android.util Base64 NO_WRAP

List of usage examples for android.util Base64 NO_WRAP

Introduction

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

Prototype

int NO_WRAP

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

Click Source Link

Document

Encoder flag bit to omit all line terminators (i.e., the output will be on one long line).

Usage

From source file:Main.java

public static byte[] generateRequestToken(byte[] countryCode, byte[] phoneNumber)
        throws NoSuchAlgorithmException {

    String signature = "MIIDMjCCAvCgAwIBAgIETCU2pDALBgcqhkjOOAQDBQAwfDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFDASBgNVBAcTC1NhbnRhIENsYXJhMRYwFAYDVQQKEw1XaGF0c0FwcCBJbmMuMRQwEgYDVQQLEwtFbmdpbmVlcmluZzEUMBIGA1UEAxMLQnJpYW4gQWN0b24wHhcNMTAwNjI1MjMwNzE2WhcNNDQwMjE1MjMwNzE2WjB8MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEUMBIGA1UEBxMLU2FudGEgQ2xhcmExFjAUBgNVBAoTDVdoYXRzQXBwIEluYy4xFDASBgNVBAsTC0VuZ2luZWVyaW5nMRQwEgYDVQQDEwtCcmlhbiBBY3RvbjCCAbgwggEsBgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8VIwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrUWU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEkO8yk8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQBTDv+z0kqA4GFAAKBgQDRGYtLgWh7zyRtQainJfCpiaUbzjJuhMgo4fVWZIvXHaSHBU1t5w//S0lDK2hiqkj8KpMWGywVov9eZxZy37V26dEqr/c2m5qZ0E+ynSu7sqUD7kGx/zeIcGT0H+KAVgkGNQCo5Uc0koLRWYHNtYoIvt5R3X6YZylbPftF/8ayWTALBgcqhkjOOAQDBQADLwAwLAIUAKYCp0d6z4QQdyN74JDfQ2WCyi8CFDUM4CaNB+ceVXdKtOrNTQcc0e+t";
    String classesMd5 = "P3b9TfNFCkkzPoVzZnm+BA=="; // 2.11.395 [*]

    byte[] key2 = Base64.decode(
            "/UIGKU1FVQa+ATM2A0za7G2KI9S/CwPYjgAbc67v7ep42eO/WeTLx1lb1cHwxpsEgF4+PmYpLd2YpGUdX/A2JQitsHzDwgcdBpUf7psX1BU=",
            Base64.DEFAULT);/*from  w w w  . ja v  a  2 s .co  m*/

    byte[] data = concat(
            concat(Base64.decode(signature, Base64.DEFAULT), Base64.decode(classesMd5, Base64.DEFAULT)),
            phoneNumber);

    byte[] opad = new byte[64];
    byte[] ipad = new byte[64];
    for (int i = 0; i < opad.length; i++) {
        opad[i] = 0x5C;
        ipad[i] = 0x36;
    }

    for (int i = 0; i < 64; i++) {
        opad[i] = (byte) ((opad[i] & 0xFF) ^ (key2[i] & 0xFF));
        ipad[i] = (byte) ((ipad[i] & 0xFF) ^ (key2[i] & 0xFF));
    }

    data = concat(ipad, data);

    MessageDigest md = MessageDigest.getInstance("SHA-1");
    md.update(data);
    byte[] firstHash = md.digest();

    data = concat(opad, firstHash);
    md = MessageDigest.getInstance("SHA-1");
    md.update(data);
    byte[] secondHash = md.digest();

    return Base64.encode(secondHash, Base64.DEFAULT | Base64.NO_WRAP);
}

From source file:es.wolfi.passman.API.Core.java

public static void requestAPIGET(Context c, String endpoint, final FutureCallback<String> callback) {
    String auth = "Basic "
            .concat(Base64.encodeToString(username.concat(":").concat(password).getBytes(), Base64.NO_WRAP));

    Ion.with(c).load(host.concat(endpoint)).setHeader("Authorization", auth) // set the header
            .asString().setCallback(new FutureCallback<String>() {
                @Override//from  w  w  w. j a  va  2  s .c  o m
                public void onCompleted(Exception e, String result) {
                    if (e == null && JSONUtils.isJSONObject(result)) {
                        try {
                            JSONObject o = new JSONObject(result);
                            if (o.getString("message").equals("Current user is not logged in")) {
                                callback.onCompleted(new Exception("401"), null);
                                return;
                            }
                        } catch (JSONException e1) {

                        }
                    }

                    callback.onCompleted(e, result);
                }
            });
}

From source file:com.knowledgecode.cordova.websocket.SendingTask.java

@Override
public void execute(JSONArray args, CallbackContext ctx) {
    try {//ww w.  j av  a 2  s .co  m
        int id = args.getInt(0);
        String data = args.getString(1);
        boolean binaryString = args.getBoolean(2);
        Connection conn = _map.get(id);

        if (conn != null) {
            if (binaryString) {
                byte[] binary = Base64.decode(data, Base64.NO_WRAP);
                conn.sendMessage(binary, 0, binary.length);
            } else {
                conn.sendMessage(data);
            }
        }
    } catch (Exception e) {
        ctx.error("send");
    }
}

From source file:com.jeffreyawest.http.HTTPAdapterImpl.java

@Override
public String GET(String pURL, String pUsername, String pPassword, String pAccept,
        HashMap<String, String> pAdditionalHeaders) {

    Log.v(LOG_TAG, "GET()");

    // Making HTTP request
    HttpGet httpGet = new HttpGet(pURL);
    httpGet.setHeader(ACCEPT_HEADER_KEY, "application/json");

    if (pUsername != null || pPassword != null) {
        String authorizationString = "Basic "
                + Base64.encodeToString((pUsername + ":" + pPassword).getBytes(), Base64.NO_WRAP);
        httpGet.setHeader("Authorization", authorizationString);
        Log.v(LOG_TAG, "Setting AUTH header: " + authorizationString);
    }/*from ww  w .jav a2 s .  c o  m*/

    String result = null;

    try {
        result = doHTTPMethod(httpGet);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:com.tapchatapp.android.service.GCMReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String messageType = mGCM.getMessageType(intent);
    if (!messageType.equals(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE)) {
        return;//from  w ww . ja va  2 s . co  m
    }

    try {
        byte[] cipherText = Base64.decode(intent.getStringExtra("payload"), Base64.URL_SAFE | Base64.NO_WRAP);
        byte[] iv = Base64.decode(intent.getStringExtra("iv"), Base64.URL_SAFE | Base64.NO_WRAP);

        byte[] key = mPusherClient.getPushKey();
        if (key == null) {
            // I don't think this will ever happen
            throw new Exception("Received push notification before receiving decryption key.");
        }

        JSONObject message = new JSONObject(new String(decrypt(cipherText, key, iv), "UTF-8"));

        Intent broadcastIntent = new Intent(TapchatApp.ACTION_MESSAGE_NOTIFY);
        addExtras(broadcastIntent, message);
        context.sendOrderedBroadcast(broadcastIntent, null);
    } catch (Exception ex) {
        Log.e(TAG, "Error parsing push notification", ex);
    }
}

From source file:cn.sharesdk.analysis.net.NetworkHelper.java

public static String Base64Gzip(String str) {
    ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    String result = null;//from  www. j a v a2  s .c o  m
    // gzip
    GZIPOutputStream gos;
    try {
        gos = new GZIPOutputStream(baos);
        int count;
        byte data[] = new byte[1024];
        while ((count = bais.read(data, 0, 1024)) != -1) {
            gos.write(data, 0, count);
        }
        gos.finish();
        gos.close();

        byte[] output = baos.toByteArray();
        baos.flush();
        baos.close();
        bais.close();

        result = Base64.encodeToString(output, Base64.NO_WRAP);

    } catch (IOException e) {
        e.printStackTrace();
        Ln.e("NetworkHelper", "Base64Gzip == >>", e);
    }

    //Ln.i("after base64gizp", result);
    return result;
}

From source file:com.mimo.service.api.MimoHttpConnection.java

/**
 * Function for Making HTTP "get" request and getting server response.
 * //from   w  w w  .  ja va2  s .co  m
 * @param p_url
 *            - Http Url
 * @throws ClientProtocolException
 * @throws IOException
 * @return HttpResponse- Returns the HttpResponse.
 */
public static synchronized HttpResponse getHttpUrlConnection(String p_url)
        throws ClientProtocolException, IOException // throws
// CustomException
{

    DefaultHttpClient m_httpClient = new DefaultHttpClient();
    HttpGet m_get = new HttpGet(p_url);

    String m_authString = MimoAPIConstants.USERNAME + ":" + MimoAPIConstants.PASSWORD;
    String m_authStringEnc = Base64.encodeToString(m_authString.getBytes(), Base64.NO_WRAP);
    m_get.addHeader(MimoAPIConstants.HEADER_TEXT_AUTHORIZATION,
            MimoAPIConstants.HEADER_TEXT_BASIC + m_authStringEnc);
    HttpResponse m_response = null;

    try {
        m_response = m_httpClient.execute(m_get);
    } catch (IllegalStateException e) {
        if (MimoAPIConstants.DEBUG) {
            Log.e(TAG, e.getMessage());
        }
    }

    return m_response;
}

From source file:org.addhen.birudo.data.net.BaseHttpClient.java

public static String base64Encode(String str) {
    byte[] bytes = str.getBytes();
    return Base64.encodeToString(bytes, Base64.NO_WRAP);
}

From source file:com.skubit.android.billing.BillingServiceBinder.java

public static String hash(byte[] message) {
    int flag = Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE;
    try {//from  ww w.  j a va  2 s  .  c om
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(message);
        return Base64.encodeToString(md.digest(), flag);
    } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
    }
    return null;
}

From source file:org.growingstems.scouting.MatchSchedule.java

public void updateSchedule(String event, Context parent, boolean toastWhenComplete) {
    HttpUtils utils = new HttpUtils();
    _parent = parent;// w w w .  ja va 2s .c o m
    toastComplete = toastWhenComplete;

    db = new DB(_parent, null);

    String url = FRC_API_URL + API_CALL + db.getCodeFromEventName(event)
            + (Prefs.getPracticeMatch(parent, false) ? "/?tournamentLevel=practice" : "/?tournamentLevel=qual");
    Map<String, String> headers = new HashMap<String, String>(1);
    headers.put("Accept", "application/json");
    headers.put("Authorization", "Basic " + Base64.encodeToString(FMSToken.token.getBytes(), Base64.NO_WRAP));
    if (url != null)
        utils.doGet(url, this, headers);

}