Giter VIP home page Giter VIP logo

Comments (6)

lpilp avatar lpilp commented on August 13, 2024

你这有两个问题:
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.

lpilp avatar lpilp commented on August 13, 2024

觉得好的话,给颗星吧 ^_^

from phpsm2sm3sm4.

sjp325 avatar sjp325 commented on August 13, 2024

bingo,解开密码是对的。你说的 解开再拼成c1c3c2 ,这部要如何解开,指点一下

from phpsm2sm3sm4.

lpilp avatar lpilp commented on August 13, 2024

https://github.com/fgrosse/PHPASN1 项目里自带着这个,可以看看上面的用法,解开

from phpsm2sm3sm4.

lpilp avatar lpilp commented on August 13, 2024

你自己封装下吧

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.

sjp325 avatar sjp325 commented on August 13, 2024

太谢谢大佬了,万分感谢

from phpsm2sm3sm4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.