|
@@ -18,9 +18,11 @@ import okhttp3.*;
|
|
|
import javax.crypto.Cipher;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.security.KeyFactory;
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -539,6 +541,36 @@ public class SRMHelperUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 私钥加密
|
|
|
+ *
|
|
|
+ * @param content 加密内容
|
|
|
+ * @param keyStr 私钥
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String encryptOld(String content, String keyStr) {
|
|
|
+ try {
|
|
|
+ //获取当前时间戳拼接加密,加密内容使用有效期3分钟
|
|
|
+ long nowTime = System.currentTimeMillis();
|
|
|
+ String contentWithTime = content + "|" + String.valueOf(nowTime);
|
|
|
+ Cipher cipher = Cipher.getInstance("RSA");
|
|
|
+ RSAPrivateKey privateKey = getPrivateKeyOld(keyStr);
|
|
|
+ cipher.init(1, privateKey);
|
|
|
+ return Base64.getUrlEncoder().encodeToString(cipher.doFinal(contentWithTime.getBytes(StandardCharsets.UTF_8)));
|
|
|
+ } catch (Exception var3) {
|
|
|
+ throw new RuntimeException("RSA encrypt failed!", var3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static RSAPrivateKey getPrivateKeyOld(String privateKey) {
|
|
|
+ try {
|
|
|
+ return (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey)));
|
|
|
+ } catch (Exception var2) {
|
|
|
+ throw new RuntimeException("RSA get Private Key failed!", var2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取SRM token
|
|
|
* @return
|