当前位置:网站首页>Object store signature generation
Object store signature generation
2022-06-24 16:22:00 【_ 12291_ seven hundred and twenty-one】
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
public class Authorization {
private static final Charset UTF8 = StandardCharsets.UTF_8;;
private static final String SecretId="";
private static final String SecretKey="";
private static final String StartTimestamp = Long.toString(System.currentTimeMillis()/1000L);
private static final String EndTimestamp = Long.toString(System.currentTimeMillis()/1000L + 30);
private static final String KeyTime= StartTimestamp + ";" + EndTimestamp;
public static String HmacSHA1(String key, String msg) throws Exception {
byte[] data = key.getBytes(UTF8);
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secretKeySpec = new SecretKeySpec(data, mac.getAlgorithm());
mac.init(secretKeySpec);
byte[] HmacSha1 = mac.doFinal(msg.getBytes(UTF8));
StringBuilder stringBuilder = new StringBuilder("");
for (int i = 0; i < HmacSha1.length; i++) {
int v = HmacSha1[i] & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return stringBuilder.toString();
}
public static String HttpString(String HttpMethod, String UriPathname, String HttpParameters, String HttpHeaders)throws Exception{
return HttpMethod + "\n" + UriPathname + "\n" + HttpParameters + "\n" + HttpHeaders + "\n";
}
public static String SHA1(String StringToSign) throws Exception{
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
messageDigest.update(StringToSign.getBytes(UTF8));
byte[] md = messageDigest.digest();
int j = md.length;
char buf[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];
}
return new String(buf);
}
public static String Sign(String HttpMethod, String UriPathname) throws Exception{
String SignKey = HmacSHA1(SecretKey, KeyTime);
String HttpStrings = HttpString(HttpMethod, UriPathname, "", "");
String StringToSign = "sha1\n"+KeyTime+"\n"+SHA1(HttpStrings)+"\n";
String Signature = HmacSHA1(SignKey, StringToSign);
String Authorization = String.format("q-sign-algorithm=%s&q-ak=%s&q-sign-time=%s&q-key-time=%s&q-header-list=%s&q-url-param-list=%s&q-signature=%s", "sha1", SecretId, KeyTime, KeyTime,"","",Signature);
return Authorization;
}
}
边栏推荐
- Some adventurer hybrid versions with potential safety hazards will be recalled
- How to open a futures account safely? Which futures companies are more reliable?
- Comparison of jmeter/k6/locust pressure measuring tools (not completed yet)
- Remain true to our original aspiration
- There are potential safety hazards Land Rover recalls some hybrid vehicles
- Inter thread communication of embedded development foundation
- Pytorch transpose convolution
- Kubernetes popular series: getting started with container Foundation
- ThinkPHP 漏洞利用工具
- [tke] troubleshooting tips for container problems
猜你喜欢

Siggraph 2022 | truly restore the hand muscles. This time, the digital human hands have bones, muscles and skin

Several common DoS attacks

C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)

存在安全隐患 路虎召回部分混动揽运

【应用推荐】最近大火的Apifox & Apipost 上手体验与选型建议

微信公众号调试与Natapp环境搭建

Wechat official account debugging and natapp environment building
![[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction](/img/32/720ffa63a90cd5d37460face3fde38.png)
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction

C. K-th Not Divisible by n(数学+思维) Codeforces Round #640 (Div. 4)

Problems encountered in the work of product manager
随机推荐
50 growers | closed door meeting of marketing circle of friends ス gathering Magic City thinking collision to help enterprise marketing growth
April 26, 2021: the length of the integer array arr is n (3 < = n < = 10^4), and each number is
Tencent releases the full platform version of reasoning framework TNN, and supports mobile terminal, desktop terminal and server terminal at the same time
Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
Understanding of deep separable convolution, block convolution, extended convolution, transposed convolution (deconvolution)
[tke] troubleshooting tips for container problems
MySQL InnoDB and MyISAM
Summer Challenge harmonyos - to do list with date effect
MySQL Advanced Series: Locks - Locks in InnoDB
PyTorch中的转置卷积详解
存在安全隐患 路虎召回部分混动揽运
Some experiences of project K several operations in the global template
基于STM32的MD5校验
山金期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
Inter thread communication of embedded development foundation
[download attached] installation and simple use of Chinese version of awvs
找出隐形资产--利用Hosts碰撞突破边界
Some experiences of K project: global template highlights
Pytorch transpose convolution
Build go command line program tool chain