MD5 with RSA in php

时光毁灭记忆、已成空白 提交于 2019-12-31 05:30:26

问题


I'm trying to implement digital signature in php as in java sample code below:

            Signature rsaSig = Signature.getInstance("MD5withRSA");
            RSAPrivateKey clientPrivateKey = readPrivateKeyFromFile(fileName);
            rsaSig.initSign(clientPrivateKey);
            String source = msg;
            byte temp[] = source.getBytes();
            rsaSig.update(temp);
            byte sig[] = rsaSig.sign();
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(sig);

My php code :

    $rsa = new Crypt_RSA();
    $rsa->loadKey('...'); // in xml format

    $plaintext = '...';

    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1); 
    $signature = $rsa->sign($plaintext);

But looks like some thing is missing. We should get same signature as java code returns.Can anybody guide me in this?


回答1:


By default phpseclib uses sha1 as the hash. You probably need to do $rsa->setHash('md5').



来源:https://stackoverflow.com/questions/22653640/md5-with-rsa-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!