From 3b1b2f1f8834fd143de4794197baef3bcd62bdfb Mon Sep 17 00:00:00 2001 From: "guangjun.hgj" Date: Wed, 8 Feb 2023 15:59:32 +0800 Subject: [PATCH] Improve the servicesignature performance. --- .../java/com/aliyun/oss/common/auth/HmacSHA1Signature.java | 7 +++++++ .../com/aliyun/oss/common/auth/HmacSHA256Signature.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/aliyun/oss/common/auth/HmacSHA1Signature.java b/src/main/java/com/aliyun/oss/common/auth/HmacSHA1Signature.java index da3e3e5b..16cc1598 100644 --- a/src/main/java/com/aliyun/oss/common/auth/HmacSHA1Signature.java +++ b/src/main/java/com/aliyun/oss/common/auth/HmacSHA1Signature.java @@ -64,4 +64,11 @@ public String computeSignature(String key, String data) { public byte[] computeHash(byte[] key, byte[] data) { return sign(key, data, macInstance, LOCK, ALGORITHM); } + + static { + try { + macInstance = Mac.getInstance(ALGORITHM); + } catch (Throwable e) { + } + } } \ No newline at end of file diff --git a/src/main/java/com/aliyun/oss/common/auth/HmacSHA256Signature.java b/src/main/java/com/aliyun/oss/common/auth/HmacSHA256Signature.java index 2b5c83f9..de3b81e8 100644 --- a/src/main/java/com/aliyun/oss/common/auth/HmacSHA256Signature.java +++ b/src/main/java/com/aliyun/oss/common/auth/HmacSHA256Signature.java @@ -64,4 +64,11 @@ public String computeSignature(String key, String data) { public byte[] computeHash(byte[] key, byte[] data) { return sign(key, data, macInstance, LOCK, ALGORITHM); } + + static { + try { + macInstance = Mac.getInstance(ALGORITHM); + } catch (Throwable e) { + } + } } \ No newline at end of file