首页 > 编程语言 >C# RSA2 SHA256 对应JAVA(SHA256withRSA)公钥验签名,CER公钥证书

C# RSA2 SHA256 对应JAVA(SHA256withRSA)公钥验签名,CER公钥证书

时间:2023-11-17 16:45:02浏览次数:40  
标签:SHA256withRSA 00 公钥 JAVA String Replace ----- KEY var

 

String timestamp = "1630905585";
String nonce = "9003323344";
String signature = "tnjIAcEISq/ClrOppv/nojeZnE/pB1wNfQC/hMTME+rQMapWzvs9v1J68ueDpVzs1RW22dNotmUVy2sM6thNFRkaOx4qQGslX6kIttwvlsJsSEIR3qrjdPdUAkbP2KDRLujspxE9X0daJ6BU+rOoJ8p4c6y1/QSOMtDJoO3EABOF4O6RFHR3N7JW8o4qcf7lOOO7D4rlAB2vw6tV8WeG+OEyJ++Q0K3V1oM5uJEIPPuJkb2qlEqVYKiYLyvIdEJ1Z5qMbC9U7rKuHdeTQPl7last/h5nd6WauzDfYPKlAjZBEPYjiDqRv6Dm+4FeNtALoy6Mg7Ruxeq1pJudfj0iKg==";
String reqBody = "{\"payOrderNo\":\"21090611012001970631000463034\",\"merchantOrderNo\":\"CH2021090613190866292\",\"orderInfo\":null,\"merchantNo\":\"822126090640003\",\"termId\":\"47781282\",\"tradeMerchantNo\":\"822126090640003\",\"tradeTermId\":\"47781282\",\"channelId\":\"10000038\",\"currency\":\"156\",\"amount\":1,\"tradeType\":\"PAY\",\"payStatus\":\"S\",\"notifyStatus\":0,\"orderCreateTime\":\"2021-09-06T05:19:43.000+00:00\",\"orderEfficientTime\":\"2021-09-06T05:19:43.000+00:00\",\"extendField\":null,\"payTime\":\"2021-09-06T05:19:43.000+00:00\",\"remark\":\"\",\"noticeNum\":1,\"sign\":null,\"notifyUrl\":null,\"notifyMode\":\"2\",\"payInfo\":\"1#1#ALIPAY#0#2021090622001432581427657317\",\"lklOrderNo\":\"2021090666210003610012\",\"crdFlg\":\"92\",\"payerId1\":\"2088702852632582\",\"payerId2\":\"rob***@126.com\",\"smCrdFlg\":\"01\",\"tradeTime\":\"20210906131943\",\"accountChannelOrderNo\":\"2021090622001432581427657317\",\"actualPayAmount\":1,\"logNo\":\"66210003610012\"}";
String preSignData = timestamp + "\n" + nonce + "\n" + reqBody + "\n";//商家特殊处理的,没有可以不需要加 \n

 


var sigeStr = preSignData;


var publicKeyCert = @"-----BEGIN PUBLIC KEY-----
MIIEMTCCAxmgAwIBAgIGAXRTgcMnMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYT
AkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAwDgYDVQQHDAdCZWlKaW5nMRcwFQYDVQQK
DA5MYWthbGEgQ28uLEx0ZDEqMCgGA1UEAwwhTGFrYWxhIE9yZ2FuaXphdGlvbiBW
YWxpZGF0aW9uIENBMB4XDTIwMTAxMDA1MjQxNFoXDTMwMTAwODA1MjQxNFowZTEL
MAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcx
FzAVBgNVBAoMDkxha2FsYSBDby4sTHRkMRkwFwYDVQQDDBBBUElHVy5MQUtBTEEu
Q09NMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1zHL54HiI8d2sLJ
lwoQji3/ln0nsvfZ/XVpOjuB+1YR6/0LdxEDMC/hxI6iH2Rm5MjwWz3dmN/6BZeI
gwGeTOWJUZFARo8UduKrlhC6gWMRpAiiGC8wA8stikc5gYB+UeFVZi/aJ0WN0cpP
JYCvPBhxhMvhVDnd4hNohnR1L7k0ypuWg0YwGjC25FaNAEFBYP9EYUyCJjE//9Z7
sMzHR9SJYCqqo6r9bOH9G6sWKuEp+osuAh+kJIxJMHfipw7w3tEcWG0hce9u/el4
cYJtg8/PPMVoccKmeCzMvarr7jdKP4lenJbtwlgyfs+JgNu60KMUJH8RS72wC9NY
uFz09wIDAQABo4HVMIHSMIGSBgNVHSMEgYowgYeAFCnH4DkZPR6CZxRn/kIqVsMo
dJHpoWekZTBjMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHQmVpSmluZzEQMA4GA1UE
BwwHQmVpSmluZzEXMBUGA1UECgwOTGFrYWxhIENvLixMdGQxFzAVBgNVBAMMDkxh
a2FsYSBSb290IENBggYBaiUALIowHQYDVR0OBBYEFJ2Kx9YZfmWpkKFnC33C0r5D
K3rFMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUA
A4IBAQBZoeU0XyH9O0LGF9R+JyGwfU/O5amoB97VeM+5n9v2z8OCiIJ8eXVGKN9L
tl9QkpTEanYwK30KkpHcJP1xfVkhPi/cCMgfTWQ5eKYC7Zm16zk7n4CP6IIgZIqm
TVGsIGKk8RzWseyWPB3lfqMDR52V1tdA1S8lJ7a2Xnpt5M2jkDXoArl3SVSwCb4D
AmThYhak48M++fUJNYII9JBGRdRGbfJ2GSFdPXgesUL2CwlReQwbW4GZkYGOg9LK
CNPK6XShlNdvgPv0CCR08KCYRwC3HZ0y1F0NjaKzYdGNPrvOq9lA495ONZCvzYDo
gmsu/kd6eqxTs/JwdaIYr4sCMg8Z
-----END PUBLIC KEY-----".Replace("-----BEGIN CERTIFICATE-----", "").Replace("-----END CERTIFICATE-----", "")
.Replace("-----BEGIN PUBLIC KEY-----", "").Replace("-----END PUBLIC KEY-----", "").Replace("\r", "").Replace("\n", "").Trim();

byte[] bytesCerContent = Convert.FromBase64String(publicKeyCert);
X509Certificate2 x509 = new X509Certificate2(bytesCerContent);
RSACryptoServiceProvider rsaPub = (RSACryptoServiceProvider)x509.PublicKey.Key;

var rsaParam = x509.GetRSAPublicKey().ExportParameters(false);
var rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(rsaParam);

 

 

byte[] messageAsByte = Encoding.GetEncoding("UTF-8").GetBytes(sigeStr);

byte[] sig256 = Convert.FromBase64String(signature);

var verify256  = rsa.VerifyData(messageAsByte, CryptoConfig.MapNameToOID("SHA256"), sig256);

 

  

 

标签:SHA256withRSA,00,公钥,JAVA,String,Replace,-----,KEY,var
From: https://www.cnblogs.com/j2ee-web-01/p/17839119.html

相关文章

  • git 切换公钥
     打开CMD1、ssh-keygen-trsa2、cdC:\Users\user5m/.ssh(输入对应的路径)3、ls(查看目录)4、catid_rsa.pub(查看当前公钥) 5、ssh-keygen-trsa-C'[email protected]'(输入git邮箱)6、复制生成的公钥并打开码云(添加SSH公钥) 完成以上操作即可拉取代码提交......
  • 二维码保存到本地Java代码
    工具类importjava.io.ByteArrayInputStream;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;publicclassWxaQrCodeUtil{/***二维码保存到本地*@parambytes*@parampath保......
  • JavaScript之splice()
    参考:https://blog.csdn.net/weixin_45726044/article/details/120151153概述splice()方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。一个参数splice(index)——>从index的位置开始,删除之后的所有元素(包括......
  • 重写Java中Arrays数组工具类提供的sort()排序函数中的比较器类Comparator的compare()
    排序方法是我们日常开发或者写功能函数,或者实现算法时,常调用的方法。有时甚至,开发人员自己还要写一写排序算法。今天,我们来修改Java官方提供的Arrays工具类中的静态排序sort()方法。反问一下,为什么要重写呢?官方提供的还不够你用?回答:确实不够用,官方默认是对数字,特别是sort比较的......
  • Java Junit单元测试(入门必看篇)
    Hii,mJinXiang⭐前言 ⭐本篇文章主要介绍单元测试工具Junit使用以及部分理论知识......
  • JAVA解析Excel文件 + 多线程 + 事务回滚
    1.项目背景:客户插入Excel文件,Ececel文件中包含大量的数据行和数据列,单线程按行读取,耗时大约半小时,体验感不好。思路:先将excel文件按行读取,存入List,然后按照100均分,n=list.szie()/100+1;n就是要开启的线程总数。(实际使用的时候,数据库连接池的数量有限制,n的大小要结合数据库连......
  • JAVA 解析Excel + 多线程 + 事务回滚(2)
    该方法为网上查询,感觉可行,并未真正尝试。主线程:packagecom.swagger.demo.service;importcom.alibaba.excel.context.AnalysisContext;importcom.alibaba.excel.event.AnalysisEventListener;importcom.swagger.demo.config.SpringJobBeanFactory;importcom.swagger.demo.m......
  • Java实现学生类继承自human类
    编写人类Human,包括私有姓名、性别、年龄,定义获取各个字段的公共方法,再定义公共的构造方法和思考方法。编写继承人类的学生类Student,增加私有的学号字段以及公共的获取学号的方法,还有公共的构造方法、学习方法,并重写toString方法获取学生数据。最后定义测试类,构造若干个学生对象......
  • Java生成随机三维数组图片推流
    生成随机的三维数组frame=np.random.randint(1,254,size=(720,1280,3)).astype(np.uint8)三维数组图片添加时间frame=cv2.putText(frame,datetime.datetime.now().__str__(),(100,100),cv2.FONT_HERSHEY_SIMPLEX,2.0,(255,255......
  • SM2加密(公钥私钥模式)
    importcn.hutool.core.util.CharsetUtil;importcn.hutool.core.util.StrUtil;importcn.hutool.crypto.SecureUtil;importcn.hutool.crypto.SmUtil;importcn.hutool.crypto.asymmetric.KeyType;importcn.hutool.crypto.asymmetric.SM2;importlombok.extern.slf4j.......