自己用 支付宝开放平台助手生成 公私钥 rsa 那种
java版本
package my_demo;
import java.io.ByteArrayOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
// spring-core-4.1.6.RELEASE 版本随意
import org.springframework.util.Base64Utils;
// fastjson2-2.0.8 版本随意
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
public class Psbc_fjapp2 {
public static void main(String[] args) throws Exception {
String rsa_publicKey = "xxxxxxxxxxxxxx";
String rsa_privateKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String paramStr = "JSON(JavaScript Object Notation, JS对象简谱)是一种轻量级的数据交换格式。它基于 ECMAScript(European Computer Manufacturers Association, 欧洲计算机协会制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。";
JSONObject paramJson = JSONObject.parseObject("{\"total\":0,\"list\":[{\"a\":\"1\",\"b\":\"2\",\"c\":\"xxxxxxxxxxxxxx\",\"d\":\"d\",\"e\":\"e\",\"cancelTime\":\"2022-11-08 15:55:55\"}]}");
String plain = JSON.toJSONString(paramJson);
plain = paramStr;// json与字符串
System.out.println("plain = " + plain);
String sign = encryptByPublicKey(plain, rsa_privateKey);
System.out.println("sign = " + sign);
System.out.println("plain = " + decryptByPrivateKey(sign, rsa_publicKey));
}
/**
* 私钥加密
*
* @param input, prik
* @return Bsae64加密好的字符串
*/
pub


1956

被折叠的 条评论
为什么被折叠?



