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:gr.ndre.scuttloid.APITask.java

protected void addAuthHeader(HttpRequestBase request) {
    String authentication = this.username + ":" + this.password;
    String encodedAuthentication = Base64.encodeToString(authentication.getBytes(), Base64.NO_WRAP);
    request.addHeader("Authorization", "Basic " + encodedAuthentication);
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleKitSupport.java

void sendDataLoggingIntent(GBDeviceEventDataLogging dataLogging) {
    Intent intent = new Intent();
    intent.putExtra("data_log_timestamp", dataLogging.timestamp);
    intent.putExtra("uuid", dataLogging.appUUID);
    intent.putExtra("data_log_uuid", dataLogging.appUUID); // Is that really the same?
    intent.putExtra("data_log_tag", dataLogging.tag);

    switch (dataLogging.command) {
    case GBDeviceEventDataLogging.COMMAND_RECEIVE_DATA:
        intent.setAction(PEBBLEKIT_ACTION_DL_RECEIVE_DATA_NEW);
        intent.putExtra("pbl_data_type", dataLogging.pebbleDataType);
        for (Object dataObject : dataLogging.data) {
            intent.putExtra("pbl_data_id", dataLogTransactionId++);
            switch (dataLogging.pebbleDataType) {
            case PebbleProtocol.TYPE_BYTEARRAY:
                intent.putExtra("pbl_data_object", Base64.encodeToString((byte[]) dataObject, Base64.NO_WRAP));
                break;
            case PebbleProtocol.TYPE_UINT:
                intent.putExtra("pbl_data_object", (Long) dataObject);
                break;
            case PebbleProtocol.TYPE_INT:
                intent.putExtra("pbl_data_object", (Integer) dataObject);
                break;
            }/*from w w  w.ja  v a2s . c o m*/
            LOG.info("broadcasting datalogging to uuid " + dataLogging.appUUID + " tag: " + dataLogging.tag
                    + "transaction id: " + dataLogTransactionId + " type: " + dataLogging.pebbleDataType);
            mContext.sendBroadcast(intent);
        }
        break;
    case GBDeviceEventDataLogging.COMMAND_FINISH_SESSION:
        intent.setAction(PEBBLEKIT_ACTION_DL_FINISH_SESSION);
        LOG.info("broadcasting datalogging finish session to uuid " + dataLogging.appUUID + " tag: "
                + dataLogging.tag);
        mContext.sendBroadcast(intent);
        break;
    default:
        LOG.warn("invalid datalog command");
    }
}

From source file:com.android.exchange.service.EasServerConnection.java

private String makeAuthString() {
    final String cs = mHostAuth.mLogin + ":" + mHostAuth.mPassword;
    return "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP);
}

From source file:org.andstatus.app.net.HttpConnectionBasic.java

/**
 * Get the HTTP digest authentication. Uses Base64 to encode credentials.
 * /*from w  w  w  .ja  va  2s.  c o m*/
 * @return String
 */
private String getCredentials() {
    // TODO: since API9 we will use getBytes(Charset.forName("US-ASCII"))
    return Base64.encodeToString((data.accountUsername + ":" + mPassword).getBytes(),
            Base64.NO_WRAP + Base64.NO_PADDING);
}

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

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

    String result = null;// w w  w .ja v  a 2s.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.i("NetworkHelper", "Base64Gzip == >>", e);
    }
    return result;
}

From source file:com.securekey.sdk.sample.VerifyQuickCodeActivity.java

/**
 * Implements AssertUserListener.assertUserComplete
 * <p>//from   w w w.  ja v a2s.  c o m
 * If successful, will forward received JWT data for a final usage for a third party
 * 
 */
@Override
public void assertUserComplete(int status, Vector<SKAudienceJwt> audiences) {
    if (status == Briidge.STATUS_OK) {

        // The JWT should be provide to a third party to be verify
        // It could be parse to see what's inside 

        dismissProgressDialog();
        for (SKAudienceJwt skAudienceJwt : audiences) {
            String[] jwtSegment = getJWSSegments(skAudienceJwt.getJwt());
            try {
                final StringBuilder message = new StringBuilder();
                message.append(new String(Base64.decode(jwtSegment[0], Base64.NO_WRAP), "UTF-8") + "\n");
                message.append(new String(Base64.decode(jwtSegment[1], Base64.NO_WRAP), "UTF-8") + "\n\n\n");
                showDialog(message.toString());

                verifyJWT(skAudienceJwt.getJwt());
            } catch (UnsupportedEncodingException e) {
                Log.e(VerifyQuickCodeActivity.class.toString(), e.getMessage());
            }
        }

    } else if (status == Briidge.STATUS_TRY_LATER_TOO_MANY_INVALID_ATTEMPTS) {
        showDialog("User suspended!");
    } else if (status == Briidge.STATUS_WRONG_CODE) {
        showDialog("Invalid code!");
    } else {
        dismissProgressDialog();
        showDialog("Failed during verification process.");
    }
}

From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java

private HttpResponse getServerResponse(String reqMethod, List<BasicNameValuePair> params) throws IOException {
    String url = getRequestUrl(reqMethod, params);
    HttpGet method = new HttpGet(url);

    DefaultHttpClient client = new DefaultHttpClient();

    // ?/*from w  ww. jav a2s.  co m*/
    String tmp = Base64.encodeToString((user_id + ":" + passwd).getBytes(), Base64.NO_WRAP);
    method.setHeader("Authorization", "Basic " + tmp);

    HttpResponse response = client.execute(method);
    int status = response.getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_OK) {
        return response;
    } else {
        //TODO:?
        return null;
    }
}

From source file:org.openbmap.soapclient.FileUploader.java

/**
 * @param file//  w  ww .  j  a v a2  s.  c  o m
 * @return
 */
private boolean performUpload(final String file) {
    // TODO check network state
    // @see http://developer.android.com/training/basics/network-ops/connecting.html

    // Adjust HttpClient parameters
    final HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    // The default value is zero, that means the timeout is not used. 
    //HttpConnectionParams.setConnectionTimeout(httpParameters, CONNECTION_TIMEOUT);
    // Set the default socket timeout (SO_TIMEOUT) 
    // in milliseconds which is the timeout for waiting for data.
    //HttpConnectionParams.setSoTimeout(httpParameters, SOCKET_TIMEOUT);
    final DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);

    final HttpPost httppost = new HttpPost(mServer);
    try {

        final String authorizationString = "Basic "
                + Base64.encodeToString((mUser + ":" + mPassword).getBytes(), Base64.NO_WRAP);
        httppost.setHeader("Authorization", authorizationString);

        final MultipartEntity entity = new MultipartEntity();

        // TODO we don't need passwords for the new service
        entity.addPart(LOGIN_FIELD, new StringBody(mUser));
        entity.addPart(PASSWORD_FIELD, new StringBody(mPassword));
        entity.addPart(FILE_FIELD, new FileBody(new File(file), "text/xml"));

        httppost.setEntity(entity);
        final HttpResponse response = httpclient.execute(httppost);

        final int reply = response.getStatusLine().getStatusCode();
        if (reply == 200) {
            Log.i(TAG, "Uploaded " + file + ": Server reply " + reply);
        } else {
            Log.w(TAG, "Error while uploading" + file + ": Server reply " + reply);
        }
        // everything is ok if we receive HTTP 200
        // TODO: redirects (301, 302) are NOT handled here 
        // thus if something changes on the server side we're dead here
        return (reply == HttpStatus.SC_OK);
    } catch (final ClientProtocolException e) {
        Log.e(TAG, e.getMessage());
    } catch (final IOException e) {
        Log.e(TAG, "I/O exception on file " + file);
    }
    return false;
}

From source file:com.danielme.muspyforandroid.services.MuspyClient.java

public UserSettings getUserSettings(String email, String pass) throws Exception {
    UserSettings userSettings = null;//from  w  ww. j av  a  2s  . c  o m
    HttpGet httpGet = new HttpGet(Constants.API.USER);
    httpGet.setHeader(CONTENT_TYPE, APPLICATION_JSON);
    httpGet.setHeader(AUTHORIZATION,
            "Basic " + Base64.encodeToString((email + ":" + pass).getBytes(), Base64.NO_WRAP));

    HttpResponse response = getDefaultHttpClient().execute(TARGETHOST, httpGet, getBasicHttpContext());

    String responseString = EntityUtils.toString(response.getEntity());

    if (checkAuth(response)) {
        userSettings = populateSettings(responseString);
    }

    return userSettings;
}

From source file:com.aegiswallet.utils.WalletUtils.java

public static List<ECKey> restoreWalletFromBackupFile(String fileName, String passOrNFC, Wallet wallet,
        boolean shouldAddKeys) {
    final List<ECKey> keys = new LinkedList<ECKey>();
    boolean nfcEncrypted;

    try {/*from w ww  . j av  a  2s  .c o m*/

        if (Constants.WALLET_BACKUP_DIRECTORY.exists() && Constants.WALLET_BACKUP_DIRECTORY.isDirectory()) {

            File file = new File(Constants.WALLET_BACKUP_DIRECTORY, fileName);

            FileInputStream fileInputStream = new FileInputStream(file);
            final BufferedReader in = new BufferedReader(
                    new InputStreamReader(fileInputStream, Constants.UTF_8));

            String x1 = null;
            String x2Encrypted = null;
            String x2Decrypted = null;
            String secretString = null;

            while (true) {
                final String line = in.readLine();
                if (line == null)
                    break; // eof

                if (line.startsWith("# "))
                    continue;

                if (line.trim().isEmpty())
                    continue;

                if (line.startsWith("#1:")) {
                    String[] splitStr = line.split(":");
                    x1 = splitStr[1];
                    continue;
                }

                if (line.startsWith("#X2:")) {

                    String[] splitStr = line.split(":");
                    String x2Base64 = splitStr[1];

                    x2Encrypted = new String(Base64.decode(x2Base64.getBytes(), Base64.NO_WRAP));
                    x2Decrypted = WalletUtils.decryptString(x2Encrypted, passOrNFC);
                    x2Decrypted = x2Decrypted.split(":")[1];
                    BigInteger secret = WalletUtils.generateSecretFromStrings("1:" + x1, "2:" + x2Decrypted,
                            null);
                    secretString = WalletUtils.convertToSha256(secret.toString());

                    continue;
                }

                if (line.startsWith("#ENCTYPE:NFC")) {
                    x2Decrypted = passOrNFC;
                    BigInteger secret = WalletUtils.generateSecretFromStrings("1:" + x1, x2Decrypted, null);
                    secretString = WalletUtils.convertToSha256(secret.toString());
                    continue;
                }

                if (line.startsWith("#ENCTYPE:PASSWORD"))
                    continue;

                String encryptedKey = new String(Base64.decode(line.getBytes(), Base64.NO_WRAP));
                String plainKey = WalletUtils.decryptString(encryptedKey, secretString);
                ECKey key = new DumpedPrivateKey(Constants.NETWORK_PARAMETERS, plainKey).getKey();

                if (!wallet.hasKey(key))
                    keys.add(key);
            }

            //Only add keys if the parameter says so. This is because the wallet may be still encrypted.
            //We dont want to add keys to an encrypted wallet. That's bad.
            if (shouldAddKeys)
                wallet.addKeys(keys);

        }

    } catch (final AddressFormatException x) {
        Log.e(TAG, "exception caught: " + x.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "exception caught: " + e.getMessage());
    } catch (Exception e) {
        Log.e(TAG, "exception caught: " + e.getMessage());
    }

    return keys;

}