Question

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?

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top