|
|
@@ -2,6 +2,9 @@ package com.fdkankan.sign;
|
|
|
|
|
|
|
|
|
import cn.hutool.crypto.digest.MD5;
|
|
|
+import cn.hutool.json.JSON;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
|
import javax.crypto.BadPaddingException;
|
|
|
import javax.crypto.Cipher;
|
|
|
@@ -15,6 +18,7 @@ import java.security.spec.InvalidKeySpecException;
|
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
import java.security.spec.X509EncodedKeySpec;
|
|
|
import java.util.Base64;
|
|
|
+import java.util.Calendar;
|
|
|
|
|
|
public class RsaUtils {
|
|
|
|
|
|
@@ -28,20 +32,23 @@ public class RsaUtils {
|
|
|
public static final int KEY_SIZE = 1024;
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- KeyPairInfo keyPair = getKeyPair();
|
|
|
- String publicKey = keyPair.getPublicKey();
|
|
|
- String privateKey = keyPair.getPrivateKey();
|
|
|
- String appId = "tsxh";
|
|
|
+// KeyPairInfo keyPair = getKeyPair();
|
|
|
+ String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCaKAIIFQjNK1mziSQkXh1WEg/keWjWlYEOn+LDwjzvpN1wEm+UFGNrv5orccS5iingtIMJxPPFlKBEMPk11TxQKHwFMJqwWDcXCIdarInjdxZXy3cbUOuE6OFgSGh9tBUANcHAiIIOKplIQLdvVc5DpVi5MGmpQVcCNOSQ4KsaDwIDAQAB";
|
|
|
+// String privateKey = keyPair.getPrivateKey();
|
|
|
+ String appId = "bf6acc5386b1106428fb1096b506661c";
|
|
|
System.out.println(appId+":");
|
|
|
- System.out.println("appId:"+ MD5.create().digestHex(appId));
|
|
|
+// System.out.println("appId:"+ MD5.create().digestHex(appId));
|
|
|
System.out.println("公钥:"+publicKey);
|
|
|
- System.out.println("私钥:"+privateKey);
|
|
|
+// System.out.println("私钥:"+privateKey);
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.set("appId", appId);
|
|
|
+ params.set("timestamp", Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
|
|
|
|
- String ciphertext = RsaUtils.encipher("123", publicKey);
|
|
|
+ String ciphertext = RsaUtils.encipher(JSONUtil.toJsonStr(params), publicKey);
|
|
|
System.out.println(String.format("密文:"+ciphertext));
|
|
|
- String deTxt = RsaUtils.decipher(ciphertext, privateKey);
|
|
|
- System.out.println(deTxt);
|
|
|
+// String deTxt = RsaUtils.decipher(ciphertext, privateKey);
|
|
|
+// System.out.println(deTxt);
|
|
|
}
|
|
|
|
|
|
/**
|