encode ( )源码实例Demo

android.util.Base64#encode ( )源码实例Demo

下面列出了android.util.Base64#encode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


protected String encodeOpenWithIntent(Intent owpIntent) {
    /*
     * Encode OpenWith intent
     * Real 3rd party apps should never run this function as DropboxApp does this entirely
     */

    Bundle extras = owpIntent.getExtras();
    extras.putString("_action", owpIntent.getAction());
    extras.putParcelable("_uri", owpIntent.getData());
    extras.putString("_type", owpIntent.getType());

    // marshall it!
    final Parcel parcel = Parcel.obtain();
    parcel.writeBundle(extras);
    byte[] b = parcel.marshall();
    parcel.recycle();
    return new String(Base64.encode(b, 0));
}
 

/**
 * Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
 *
 * @param bitmap
 */
public void processPicture(Bitmap bitmap) {
    ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
    try {
        if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
            byte[] code = jpeg_data.toByteArray();
            byte[] output = Base64.encode(code, Base64.DEFAULT);
            String js_out = new String(output);
            this.callbackContext.success(js_out);
            js_out = null;
            output = null;
            code = null;
        }
    } catch (Exception e) {
        this.failPicture("Error compressing image.");
    }
    jpeg_data = null;
}
 

/**
 * Returns an X-Geo HTTP header string if:
 *  1. The current mode is not incognito.
 *  2. The url is a google search URL (e.g. www.google.co.uk/search?q=cars), and
 *  3. The user has not disabled sharing location with this url, and
 *  4. There is a valid and recent location available.
 *
 * Returns null otherwise.
 *
 * @param context The Context used to get the device location.
 * @param url The URL of the request with which this header will be sent.
 * @param isIncognito Whether the request will happen in an incognito tab.
 * @return The X-Geo header string or null.
 */
public static String getGeoHeader(Context context, String url, boolean isIncognito) {
    if (!isGeoHeaderEnabledForUrl(context, url, isIncognito, true)) {
        return null;
    }

    // Only send X-Geo header if there's a fresh location available.
    Location location = GeolocationTracker.getLastKnownLocation(context);
    if (location == null) {
        recordHistogram(UMA_LOCATION_NOT_AVAILABLE);
        return null;
    }
    if (GeolocationTracker.getLocationAge(location) > MAX_LOCATION_AGE) {
        recordHistogram(UMA_LOCATION_STALE);
        return null;
    }

    recordHistogram(UMA_HEADER_SENT);

    // Timestamp in microseconds since the UNIX epoch.
    long timestamp = location.getTime() * 1000;
    // Latitude times 1e7.
    int latitude = (int) (location.getLatitude() * 10000000);
    // Longitude times 1e7.
    int longitude = (int) (location.getLongitude() * 10000000);
    // Radius of 68% accuracy in mm.
    int radius = (int) (location.getAccuracy() * 1000);

    // Encode location using ascii protobuf format followed by base64 encoding.
    // https://goto.google.com/partner_location_proto
    String locationAscii = String.format(Locale.US,
            "role:1 producer:12 timestamp:%d latlng{latitude_e7:%d longitude_e7:%d} radius:%d",
            timestamp, latitude, longitude, radius);
    String locationBase64 = new String(Base64.encode(locationAscii.getBytes(), Base64.NO_WRAP));

    return "X-Geo: a " + locationBase64;
}
 

PasswordNetworkManager(@NonNull ShaarliAccount account) {
    this.mShaarliUrl = account.getUrlShaarli();
    this.mUsername = account.getUsername();
    this.mPassword = account.getPassword();
    this.mValidateCert = account.isValidateCert();

    if (!"".equals(account.getBasicAuthUsername()) && !"".equals(account.getBasicAuthPassword())) {
        String login = account.getBasicAuthUsername() + ":" + account.getBasicAuthPassword();
        this.mBasicAuth = new String(Base64.encode(login.getBytes(), Base64.NO_WRAP));
    } else {
        this.mBasicAuth = "";
    }
}
 
源代码5 项目: o2oa   文件: CryptDES.java

/**
 * Decrypt a base64 encoded, DES encrypted string and return
 * the unencrypted string.
 * @param encryptedString The base64 encoded string to decrypt.
 * @return String The decrypted string.
 * @throws Exception If an error occurs.
 */
public String decryptBase64 (String encryptedString) throws Exception {
    // Encode bytes to base64 to get a string
    byte [] decodedBytes = Base64.encode(encryptedString.getBytes(), Base64.DEFAULT);
    // Decrypt
    byte[] unencryptedByteArray = decryptCipher.doFinal(decodedBytes);
    // Decode using utf-8
    return new String(unencryptedByteArray, "UTF8");
}
 
源代码6 项目: unity-bluetooth   文件: BServiceUtil.java

public static String encodeBase64(byte[] data) {
    if (data == null) {
        return null;
    }
    byte[] encode = Base64.encode(data, Base64.DEFAULT);
    String str = null;
    try {
        str = new String(encode, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    }
    return str;
}
 
源代码7 项目: OpenHub   文件: AESEncrypting.java

/**
 * AES加密
 * @param input 加密字符串
 * @param key 密钥,密钥必须是16位的
 * @return
 */
public static String encrypt(@NonNull String input, @NonNull String key){
  byte[] crypted = null;
  try{
	  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
      Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      cipher.init(Cipher.ENCRYPT_MODE, skey);
      crypted = cipher.doFinal(input.getBytes());
    }catch(Exception e){
    	System.out.println(e.toString());
    }
    return new String(Base64.encode(crypted, Base64.DEFAULT));
}
 
源代码8 项目: UltimateAndroid   文件: TripleDES.java

public static byte[] Base64encodingByte(byte[] context,int type) {
    byte[] result;
    if (judgeVerionOfSdk() > 17) {
        result= Base64.encode(context, type);
    } else {
        result= com.marshalchen.common.commonUtils.urlUtils.Base64.encodeBytesToBytes(context);
    }
    return result;
}
 
源代码9 项目: fooXposed   文件: Base64Util.java

public static String encrypt(String text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    } else {
        return new String(Base64.encode(text.getBytes(UTF8), Base64.NO_WRAP), UTF8);
    }
}
 
源代码10 项目: OpenYOLO-Android   文件: LoginViewModel.java

private String base64Sha256Hash(byte[] data) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] sha256Bytes = digest.digest(data);
        return new String(
                Base64.encode(sha256Bytes, Base64.NO_WRAP | Base64.URL_SAFE),
                Charset.forName("UTF-8"));
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("SHA-256 not supported on this platform!");
    }
}
 
源代码11 项目: JWTDecode.Android   文件: JWTTest.java

private String encodeString(String source) {
    byte[] bytes = Base64.encode(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING);
    return new String(bytes, Charset.defaultCharset());
}
 
源代码12 项目: Android-utils   文件: EncodeUtils.java

public static byte[] base64Encode(final byte[] input) {
    if (input == null || input.length == 0) return new byte[0];
    return Base64.encode(input, Base64.NO_WRAP);
}
 
源代码13 项目: FastAndroid   文件: EncryptTool.java

private static byte[] base64Encode(final byte[] input) {
    return Base64.encode(input, Base64.NO_WRAP);
}
 
源代码14 项目: styT   文件: UserCenterAPIActivity.java

private String encodeData(String data) throws UnsupportedEncodingException {
	//进行BASE64编码,URL_SAFE/NO_WRAP/NO_PADDING
	return new String(Base64.encode(data.getBytes("utf-8"), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING), "utf-8");
}
 
源代码15 项目: text_converter   文件: StringXor.java

@NonNull
public static String encode(String s, String key) {
    byte[] xor = xor(s.getBytes(), key.getBytes());
    byte[] encoded = Base64.encode(xor, Base64.DEFAULT);
    return new String(encoded);
}
 
源代码16 项目: Hook   文件: BaseApi.java

public static void send(final Context context, String url, final Object param, final Class clazz, final int TAG) {


        if (!url.startsWith("http")) {
            url = "http://sanlicun.cn/" + url;
        }
        Log.d("tag", url);


        final RequestQueue requestQueue = Volley.newRequestQueue(context);


        final String finalUrl = url;
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.i("tag", "onResponse:" + response);
                        if (response.equals("success")) {
                            index=0;
                            return;
                        }

                        if(index<3){
                            PayHelperUtils.sendmsg(context,"发送结果失败");
                            index++;
                            send(context, finalUrl, param, clazz, TAG);
                        }



                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                if(index<3){
                    PayHelperUtils.sendmsg(context,"发送结果失败");
                    index++;
                    send(context, finalUrl, param, clazz, TAG);
                }


            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();

                try {
                    String p = new String(Base64.encode(JSONObject.toJSONString(param).getBytes(), Base64.DEFAULT), "utf-8");
                    Log.d("tag", p);

                    map.put("param", p);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }


                return map;
            }
        };

        requestQueue.add(stringRequest);

    }
 
源代码17 项目: RxTools-master   文件: RxEncodeTool.java

/**
 * Base64URL安全编码
 * <p>将Base64中的URL非法字符�?,/=转为其他字符, 见RFC3548</p>
 *
 * @param input 要Base64URL安全编码的字符串
 * @return Base64URL安全编码后的字符串
 */
public static byte[] base64UrlSafeEncode(String input) {
    return Base64.encode(input.getBytes(), Base64.URL_SAFE);
}
 
源代码18 项目: ZhiHu-TopAnswer   文件: EncodeUtils.java

/**
 * Base64编码
 *
 * @param input 要编码的字节数组
 * @return Base64编码后的字符串
 */
public static byte[] base64Encode(byte[] input) {
    return Base64.encode(input, Base64.NO_WRAP);
}
 
源代码19 项目: Android-UtilCode   文件: EncryptUtils.java

/**
 * Base64编码
 *
 * @param input 要编码的字节数组
 * @return Base64编码后的字符串
 */
private static byte[] base64Encode(byte[] input) {
    return Base64.encode(input, Base64.NO_WRAP);
}
 
源代码20 项目: AndroidUtilCode   文件: EncodeUtils.java

/**
 * Return Base64-encode bytes.
 *
 * @param input The input.
 * @return Base64-encode bytes
 */
public static byte[] base64Encode(final byte[] input) {
    if (input == null || input.length == 0) return new byte[0];
    return Base64.encode(input, Base64.NO_WRAP);
}
 
点击广告?(赏赐笔者)
 方法所在类