本文整理汇总了Java中com.qiniu.android.utils.UrlSafeBase64类的典型用法代码示例。如果您正苦于以下问题:Java UrlSafeBase64类的具体用法?Java UrlSafeBase64怎么用?Java UrlSafeBase64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UrlSafeBase64类属于com.qiniu.android.utils包,在下文中一共展示了UrlSafeBase64类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parse
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public static UpToken parse(String token) {
try {
String[] t = token.split(":");
if (t.length != 3) {
return null;
}
try {
JSONObject obj = new JSONObject(new String(UrlSafeBase64.decode(t[2])));
if (obj.optString("scope").equals("") || obj.optInt("deadline") == 0) {
return null;
}
return new UpToken(obj, token);
} catch (JSONException e) {
return null;
}
} catch (Exception e2) {
return null;
}
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:UpToken.java
示例2: getUpToken
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public static String getUpToken() {
try {
// 1.确定上传策略
// 2.将上传策略序列化称为json格式
JSONObject jsonObj = new JSONObject();
long deadline = System.currentTimeMillis() / 1000 + 3600;
jsonObj.put("deadline", deadline);
jsonObj.put("scope", QINIU_BUCKNAME);
// 3.对json序列化后的上传策略进行URL安全的Base64编码,得到如下encoded
String encodedPutPolicy = UrlSafeBase64.encodeToString(jsonObj.toString().getBytes());
// 4.用SecretKey对编码后的上传策略进行HMAC-SHA1加密,并且做URL安全的Base64编码,得到如下的encodedSigned
byte[] sign = HmacSHA1Encrypt(encodedPutPolicy, QINIU_SK);
String encodedSigned = UrlSafeBase64.encodeToString(sign);
// 5.将 AccessKey、encodeSigned 和 encoded 用 “:” 连接起来,得到如下的UploadToken
String uploadToken = QINIU_AK + ":" + encodedSigned + ":" + encodedPutPolicy;
return uploadToken;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
开发者ID:LegendKe,项目名称:MyTravelingDiary,代码行数:22,代码来源:QiniuHelper.java
示例3: signRequest
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
/**
* 生成HTTP请求签名字符串
*
* @param urlString
* @param body
* @param contentType
* @return
*/
public String signRequest(String urlString, byte[] body, String contentType) {
URI uri = URI.create(urlString);
String path = uri.getRawPath();
String query = uri.getRawQuery();
Mac mac = createMac();
mac.update(StringUtils.utf8Bytes(path));
if (query != null && query.length() != 0) {
mac.update((byte) ('?'));
mac.update(StringUtils.utf8Bytes(query));
}
mac.update((byte) '\n');
if (body != null && body.length > 0 && !StringUtils.isNullOrEmpty(contentType)) {
if (contentType.equals(Client.FormMime)
|| contentType.equals(Client.JsonMime)) {
mac.update(body);
}
}
String digest = UrlSafeBase64.encodeToString(mac.doFinal());
return this.accessKey + ":" + digest;
}
开发者ID:luania,项目名称:witchpot,代码行数:34,代码来源:Auth.java
示例4: set
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public void set(String key, byte[] data) {
IOException e;
FileOutputStream fo = null;
try {
FileOutputStream fo2 = new FileOutputStream(new File(this.directory, UrlSafeBase64
.encodeToString(key)));
try {
fo2.write(data);
fo = fo2;
} catch (IOException e2) {
e = e2;
fo = fo2;
e.printStackTrace();
if (fo == null) {
try {
fo.close();
} catch (IOException e3) {
e3.printStackTrace();
return;
}
}
}
} catch (IOException e4) {
e3 = e4;
e3.printStackTrace();
if (fo == null) {
fo.close();
}
}
if (fo == null) {
fo.close();
}
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:34,代码来源:FileRecorder.java
示例5: sign
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public String sign(byte[] data) {
Mac mac = createMac();
String encodedSign = UrlSafeBase64.encodeToString(mac.doFinal(data));
return this.accessKey + ":" + encodedSign;
}
开发者ID:lqxue,项目名称:QiNiuTest,代码行数:6,代码来源:Auth.java
示例6: signWithData
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public String signWithData(byte[] data) {
String s = UrlSafeBase64.encodeToString(data);
return sign(StringUtils.utf8Bytes(s)) + ":" + s;
}
开发者ID:lqxue,项目名称:QiNiuTest,代码行数:5,代码来源:Auth.java
示例7: get
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public byte[] get(String key) {
IOException e;
File f = new File(this.directory, UrlSafeBase64.encodeToString(key));
FileInputStream fi = null;
byte[] data = null;
int read = 0;
try {
if (outOfDate(f)) {
f.delete();
return null;
}
data = new byte[((int) f.length())];
FileInputStream fi2 = new FileInputStream(f);
try {
read = fi2.read(data);
fi = fi2;
} catch (IOException e2) {
e = e2;
fi = fi2;
e.printStackTrace();
if (fi != null) {
try {
fi.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (read != 0) {
return null;
}
return data;
}
if (fi != null) {
fi.close();
}
if (read != 0) {
return data;
}
return null;
} catch (IOException e4) {
e3 = e4;
e3.printStackTrace();
if (fi != null) {
fi.close();
}
if (read != 0) {
return data;
}
return null;
}
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:52,代码来源:FileRecorder.java
示例8: del
import com.qiniu.android.utils.UrlSafeBase64; //导入依赖的package包/类
public void del(String key) {
new File(this.directory, UrlSafeBase64.encodeToString(key)).delete();
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:FileRecorder.java
注:本文中的com.qiniu.android.utils.UrlSafeBase64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论