本文整理汇总了Java中com.loopj.android.http.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于com.loopj.android.http包,在下文中一共展示了Base64类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequestHeaders
import com.loopj.android.http.Base64; //导入依赖的package包/类
@Override
public Header[] getRequestHeaders() {
List<Header> headers = getRequestHeadersList();
// Add authentication header.
if (userName != null && passWord != null) {
byte[] base64bytes = Base64.encode(
(userName + ":" + passWord).getBytes(),
Base64.DEFAULT
);
String credentials = new String(base64bytes);
headers.add(new BasicHeader(HEADER_AUTHORIZATION, HEADER_BASIC + " " + credentials));
}
return headers.toArray(new Header[headers.size()]);
}
示例2: hmac_sha1
import com.loopj.android.http.Base64; //导入依赖的package包/类
private static String hmac_sha1(String key,String message) {
String reString = null;
try {
byte[] data = key.getBytes("UTF-8");
//根据给定的字节数组构造一个密钥,第二参数指定一个密钥算法的名称
SecretKey secretKey = new SecretKeySpec(data, "HmacSHA1");
//生成一个指定 Mac 算法 的 Mac 对象
Mac mac = Mac.getInstance("HmacSHA1");
//用给定密钥初始化 Mac 对象
mac.init(secretKey);
byte[] text = message.getBytes("UTF-8");
//完成 Mac 操作
byte[] text1 = mac.doFinal(text);
reString = Base64.encodeToString(text1, Base64.URL_SAFE);
} catch (Exception e)
{
e.printStackTrace();
}
return reString;
}
示例3: base64FromBitmap
import com.loopj.android.http.Base64; //导入依赖的package包/类
/**
* Convert a bitmap object to a Base64 encoded string.
* @param image The image to convert.
* @return A String in Base64 containing the image data.
*/
protected String base64FromBitmap(Bitmap image) {
// Create a compressed byte array from the provided image. 80% JPEG seems to be enough
// for accurate recognition
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
image.compress(CompressFormat.JPEG, 80, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encoded = Base64.encodeToString(byteArray, 0);
return encoded;
}
示例4: makeSign
import com.loopj.android.http.Base64; //导入依赖的package包/类
/**
* 生成签名字符串
*
* @param url
* 网络地址
* @param method
* 请求方法
* @param params
* 请求参数
* @param appsecret
* 签名密钥
* @param dbg
* 是否开启调试:调式模式可打印签名日志
* @return
*/
public String makeSign(String url, String method, RequestParams params, String appsecret, boolean dbg) {
StringBuilder sb = new StringBuilder();
sb.append(method).append("&");
sb.append(Uri.encode(url)).append("&");
// 排序
List<BasicNameValuePair> basicNameValuePairs = params.getParamsList();
Collections.sort(basicNameValuePairs, paramsCompre);
String paramStr = URLEncodedUtils.format(basicNameValuePairs, "UTF-8");
sb.append(Uri.encode(paramStr));
String digit = TXSHAUtil.getSHA1(sb.toString());
byte[] encrypt = TXXXTEA.encrypt(digit.getBytes(), appsecret.getBytes());
String base64 = Base64.encodeToString(encrypt, Base64.DEFAULT);
String sign = Uri.encode(base64);
if (dbg) {
TXDebug.o(new Exception(), "url : " + sb.toString());
TXDebug.o(new Exception(), "digit : " + digit);
TXDebug.o(new Exception(), "base64 : " + base64);
TXDebug.o(new Exception(), "sign : " + sign);
}
params.put("sign", sign);
return sign;
}
示例5: getUploadToken
import com.loopj.android.http.Base64; //导入依赖的package包/类
public static String getUploadToken(String fileName) {
String token = null;
try{
//一:将上传策略转换成Json格式
JSONObject policy = new JSONObject();
StringBuilder scope = new StringBuilder();
scope.append(bucket);
scope.append(":");
scope.append(fileName);
policy.put("scope",scope.toString()); //只允许上传指定key的文件,而key就是文件名
scope = null;
policy.put("deadline",getTimer());
//policy.put("insertOnly",1); //不允许修改
//policy.put("callbackFetchKey",1); //启动fetchKey上传模式
// policy.put("returnBody ","{\"name\" : \"$(fname))}");
Log.d("policy",policy.toString());
//二:对JSON编码的上传策略进行URL安全的Base64编码,得到待签名字符串:
String encodPutPolicy = Base64.encodeToString(policy.toString().getBytes("UTF-8"), Base64.URL_SAFE);
Log.i("encodPutPolicy","encodPutPolicy is " + encodPutPolicy);
//三:使用SecertKey对上一步生成的待签名字符串计算HMAC-SHA1签名:并对签名进行URL安全的Base64编码:
String encodSign = hmac_sha1(SK,encodPutPolicy);
Log.i("encodSign","encodSign is " + encodSign);
//五:将AccessKey、encodedSign和encodedPutPolicy用:连接起来:
token = AK + ':' + encodSign + ':' + encodPutPolicy;
Log.i("token","token is " + token);
}catch (Exception e) {
e.printStackTrace();
}
return token;
}