Comments (6)
你这有两个问题:
1.这里如果构造的时候加了base64, 下面一行就不要再转成hex, 直接使用,
$sm2 = new RtSm2();
$encryptKey = bin2hex(base64_decode($encryptKey));
$key = $sm2->doDecrypt($encryptKey,$privateKey);
// 或者
$sm2 = new RtSm2('base64');
$key = $sm2->doDecrypt($encryptKey,$privateKey);
问题2:
encryptKey 正常情况应该是 c1c3c2, 但招行就喜欢和人不一样, 给的是 asn1(c1x,c1y, c3,c2), 我这个函数暂还不支持这个,你只要解开再拼成 c1c3c2的形式就行了, 最后解开后是密码是 “b0xxxxxxxxxxxc8”的16字节明文,
from phpsm2sm3sm4.
觉得好的话,给颗星吧 ^_^
from phpsm2sm3sm4.
bingo,解开密码是对的。你说的 解开再拼成c1c3c2 ,这部要如何解开,指点一下
from phpsm2sm3sm4.
https://github.com/fgrosse/PHPASN1 项目里自带着这个,可以看看上面的用法,解开
from phpsm2sm3sm4.
你自己封装下吧
use FG\ASN1\ASNObject;
$data = 'MHgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyKOw=';
$binaryData = base64_decode($data);
$asnObject = ASNObject::fromBinary($binaryData);
$result = array();
foreach($asnObject as $object){
$result[] = $object->__toString();
}
$c1x = gmp_strval(gmp_init($result[0],10),16);
$c1y = gmp_strval(gmp_init($result[1],10),16);
$c1x = padding_zero($c1x);
$c1y = padding_zero($c1y);
$c3 = $result[2];
$c2 = $result[3];
$ret = strtolower("{$c1x}{$c1y}{$c3}{$c2}");
function padding_zero($hex,$len = 64) {
$left = $len - strlen($hex) ;
if($left >0){
$hex = str_repeat('0',$left) . $hex;
}
return $hex;
}
from phpsm2sm3sm4.
太谢谢大佬了,万分感谢
from phpsm2sm3sm4.
Related Issues (20)
- useDerandomizedSignatures属性设置 HOT 5
- sm2加密出来的java好像不认 HOT 3
- 请教关于掌上生活 Sm3WithSm2 签名问题 HOT 3
- 请问现在还需要gmp扩展的支持吗? HOT 2
- 和java对接,SM2无法解密数据 HOT 3
- sm2对接java无法解密 HOT 4
- 怎么无法下载扩展呢composer HOT 1
- sm2怎么取消asn1签名 HOT 4
- 你好大佬 我用你的验证包 和https://const.net.cn/tool/sm2/verify/ 这个网站相互验签总是失败怎么回事 HOT 2
- 您好,对接的是浦发的sm2 HOT 4
- 关于招行的验签 HOT 3
- SM2解密求助 | PHP对接Java HOT 6
- 请问服务器openssl版本需要多少能正常使用sm2加密解密呢? HOT 6
- 还是招行问题,看完了issue没有理解,求大佬解答,感谢 HOT 11
- 对接招行CBS8,Invalid Sign HOT 19
- sm2加密公钥 HOT 3
- 可以再发布一个最新的版本么? HOT 4
- 1.0.7版本 不兼容 以前版本 HOT 4
- RtSm2 verifySignOutKey方法返回值标注应为 bool HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpsm2sm3sm4.