|
@ -3,11 +3,21 @@ package com.css.oa.supervision.waitexec.service.impl;
|
3
|
3
|
import org.apache.commons.codec.binary.Hex;
|
4
|
4
|
import org.junit.Test;
|
5
|
5
|
|
|
6
|
import java.security.InvalidKeyException;
|
6
|
7
|
import java.security.MessageDigest;
|
7
|
8
|
import java.security.NoSuchAlgorithmException;
|
8
|
9
|
import java.text.DecimalFormat;
|
9
|
10
|
import java.text.NumberFormat;
|
10
|
11
|
|
|
12
|
import java.security.MessageDigest;
|
|
13
|
import java.util.Date;
|
|
14
|
import javax.crypto.Mac;
|
|
15
|
import javax.crypto.spec.SecretKeySpec;
|
|
16
|
|
|
17
|
import static javax.xml.crypto.dsig.SignatureMethod.HMAC_SHA1;
|
|
18
|
|
|
19
|
//import static javax.xml.crypto.dsig.SignatureMethod.HMAC_SHA1;
|
|
20
|
|
11
|
21
|
public class MyTest {
|
12
|
22
|
//
|
13
|
23
|
// @Test
|
|
@ -35,15 +45,36 @@ public class MyTest {
|
35
|
45
|
// //return md5Result;
|
36
|
46
|
// }
|
37
|
47
|
|
38
|
|
@Test
|
39
|
|
public void numFormat() {
|
40
|
|
double result1=0.51111122111111;
|
41
|
|
DecimalFormat df = new DecimalFormat("0.0%");
|
42
|
|
String r = df.format(result1);
|
43
|
|
System.out.println(r);//great
|
|
48
|
// @Test
|
|
49
|
// public void numFormat() {
|
|
50
|
// double result1=0.51111122111111;
|
|
51
|
// DecimalFormat df = new DecimalFormat("0.0%");
|
|
52
|
// String r = df.format(result1);
|
|
53
|
// System.out.println(r);//great
|
|
54
|
//
|
|
55
|
//
|
|
56
|
//// System.out.println("numberString => "+numberString);
|
|
57
|
// }
|
44
|
58
|
|
|
59
|
@Test
|
|
60
|
public void a3() {
|
|
61
|
String accessKeyId = "hellocode";
|
|
62
|
String secureKey = "f53d3819d5e265984fc8911d36377280";
|
45
|
63
|
|
46
|
|
// System.out.println("numberString => "+numberString);
|
|
64
|
long timestamp = 1619770939;//new Date().getTime();
|
|
65
|
try {
|
|
66
|
String signature = hmacsha1((accessKeyId + "\n" + timestamp).getBytes(), secureKey.getBytes());
|
|
67
|
System.out.println(signature);
|
|
68
|
} catch (Exception e) {
|
|
69
|
e.printStackTrace();
|
|
70
|
}
|
47
|
71
|
}
|
48
|
72
|
|
|
73
|
private String hmacsha1(byte[] data, byte[] key) throws Exception {
|
|
74
|
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
|
|
75
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
76
|
mac.init(signingKey);
|
|
77
|
byte[] rawHmac = mac.doFinal(data);
|
|
78
|
return org.apache.commons.codec.binary.Base64.encodeBase64String(rawHmac);
|
|
79
|
}
|
49
|
80
|
}
|