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:com.phonemetra.account.util.AccountUtils.java

public static byte[] getHmacSecret(AccountManager accountManager, Account account) {
    if (account == null) {
        if (Account.DEBUG)
            Log.d(TAG, "No Account configured!");
        return null;
    }/*  www  .ja  va  2  s  .  c  o  m*/
    return Base64.decode(accountManager.getUserData(account, Account.ACCOUNT_EXTRA_HMAC_SECRET),
            Base64.NO_WRAP);
}

From source file:org.jboss.aerogear.android.unifiedpush.gcm.AeroGearGCMPushRegistrar.java

private String getHashedAuth(String username, char[] password) {
    StringBuilder headerValueBuilder = new StringBuilder(AUTHORIZATION_METHOD).append(" ");
    String unhashedCredentials = new StringBuilder(username).append(":").append(password).toString();
    String hashedCrentials = Base64.encodeToString(unhashedCredentials.getBytes(),
            Base64.DEFAULT | Base64.NO_WRAP);
    return headerValueBuilder.append(hashedCrentials).toString();
}

From source file:at.jclehner.rxdroid.Backup.java

private static String passwordToKey(String password) {
    if (password.length() == 0)
        return null;

    try {//from  w w w . ja  v  a  2 s.  com
        final MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update("RxDroid".getBytes());
        return Base64.encodeToString(md.digest(password.getBytes("UTF-8")), Base64.NO_WRAP);
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        throw new WrappedCheckedException(e);
    }
}

From source file:de.electricdynamite.pasty.PastyClient.java

private String getHTTPBasicAuth() {
    if (basicAuthInfo == null) {
        String auth = username + ":" + password;
        this.basicAuthInfo = "Basic " + Base64.encodeToString(auth.getBytes(), Base64.NO_WRAP);
        auth = null;/* w ww .j  a v  a 2  s  . c o m*/
    }
    return this.basicAuthInfo;
}

From source file:com.hybris.mobile.data.WebServiceDataProvider.java

/**
 * Synchronous call for logging in//from  w w  w .ja va 2s . c om
 * 
 * @param httpBody
 * @return The data from the server as a string, in almost all cases JSON
 * @throws MalformedURLException
 * @throws IOException
 * @throws JSONException
 */
public static String getLoginResponse(Bundle httpBody) throws MalformedURLException, IOException {
    String response = "";
    URL url = new URL(WebServiceAuthProvider.tokenURL());
    trustAllHosts();
    HttpsURLConnection connection = createSecureConnection(url);
    connection.setHostnameVerifier(DO_NOT_VERIFY);
    String authString = "mobile_android:secret";
    String authValue = "Basic " + Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);

    connection.setRequestMethod("POST");
    connection.setRequestProperty("Authorization", authValue);
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.connect();

    OutputStream os = new BufferedOutputStream(connection.getOutputStream());
    os.write(encodePostBody(httpBody).getBytes());
    os.flush();
    try {
        LoggingUtils.d(LOG_TAG, connection.toString());
        response = readFromStream(connection.getInputStream());
    } catch (MalformedURLException e) {
        LoggingUtils.e(LOG_TAG,
                "Error reading stream \"" + connection.getInputStream() + "\". " + e.getLocalizedMessage(),
                null);
    } catch (IOException e) {
        response = readFromStream(connection.getErrorStream());
    } finally {
        connection.disconnect();
    }

    return response;
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

private void putBase64(CallbackContext callbackContext, JSONArray args) {
    try {//w  ww  .j  av a 2 s.c om
        String namespace = args.getString(0);
        String key = args.getString(1);
        String base64 = args.getString(2);
        byte[] data = Base64.decode(base64, Base64.NO_WRAP);

        mWinch.getNamespace(namespace).put(key, data);
        callbackContext.success();
    } catch (WinchError e) {
        e.printStackTrace();
        PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage());
        callbackContext.sendPluginResult(r);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:nl.hnogames.domoticzapi.Utils.RequestUtil.java

public static ImageLoader getImageLoader(final Domoticz domoticz, final SessionUtil sessionUtil,
        Context context) {/* w w w. java 2  s.co  m*/
    if (domoticz == null)
        return null;

    ImageLoader.ImageCache imageCache = new BitmapLruCache();
    return new ImageLoader(Volley.newRequestQueue(context), imageCache) {
        @SuppressWarnings("deprecation")
        @Override
        protected com.android.volley.Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth,
                int maxHeight, ImageView.ScaleType scaleType, final String cacheKey) {
            return new ImageRequest(requestUrl, new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    onGetImageSuccess(cacheKey, response);
                }
            }, maxWidth, maxHeight, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    onGetImageError(cacheKey, error);
                }
            }) {

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> headers = super.getHeaders();

                    if (headers == null || headers.equals(Collections.emptyMap())) {
                        headers = new HashMap<>();
                    }

                    String credentials = domoticz.getUserCredentials(Domoticz.Authentication.USERNAME) + ":"
                            + domoticz.getUserCredentials(Domoticz.Authentication.PASSWORD);
                    String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(),
                            Base64.NO_WRAP);

                    headers.put("Authorization", "Basic " + base64EncodedCredentials);
                    headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                    headers.put("Accept-Language", "en-US,en;q=0.7,nl;q=0.3");
                    headers.put("Accept-Encoding", "gzip, deflate");

                    sessionUtil.addSessionCookie(headers);
                    return headers;
                }
            };
        }
    };
}

From source file:com.mpower.mintel.android.utilities.WebUtils.java

public static String getSHA512(String input) {
    String retval = "";
    try {//from ww w .j a  v a 2 s.  c  om
        MessageDigest m = MessageDigest.getInstance("SHA-512");
        byte[] out = m.digest(input.getBytes());
        retval = Base64.encodeToString(out, Base64.NO_WRAP);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    return retval;
}

From source file:com.ledger.android.u2f.bridge.MainActivity.java

private String createClientData(U2FContext context) {
    try {//from  w  ww. ja v a  2s.c  o m
        JSONObject clientData = new JSONObject();
        clientData.put(TAG_JSON_TYP, (context.isSign() ? SIGN_RESPONSE_TYP : REGISTER_RESPONSE_TYP));
        clientData.put(TAG_JSON_CHALLENGE, Base64.encodeToString(context.getChallenge(),
                Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING));
        clientData.put(TAG_JSON_ORIGIN, context.getAppId());
        clientData.put(TAG_JSON_CID_PUBKEY, CID_UNAVAILABLE);
        return clientData.toString();
    } catch (Exception e) {
        Log.e(TAG, "Error encoding client data");
        return null;
    }
}

From source file:com.collecdoo.fragment.main.RegisterDriverPhotoFragment.java

private String encodeBitmapBase64(Bitmap bitmap) {
    if (bitmap == null)
        return "";

    return Base64.encodeToString(UIHelper.convertBitmapToByteArray(bitmap), Base64.NO_WRAP);
}