简体   繁体   中英

Windows to verify signature from Open SSL php

I use PHP to sign a string with openssl_sign. So far all ok.

The problem is that I want to verify the signature from Windows. For that I pass the certificate, the message, and it's signature to the windows app. How do I use CryptVerifyDetachedMessageSignature to force using the certificate that the PHP code used?

I tried it, but it returns "asn1 bad tag value met" on the signature created by PHP ...

Thanks...

It's hard to say since you haven't posted your code or a sample signature / plaintext / key. But, in lieu of that, here's how I'd do it (with phpseclib):

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
//$rsa->setPassword('password');
$rsa->loadKey('...'); // private key

$plaintext = '...';

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

$rsa->loadKey('...'); // public key
echo $rsa->verify($plaintext, $signature) ? 'verified' : 'unverified';
?>

If the signature mode is PSS just do $rsa->setSignatureMode() (without any parameters) instead.

If the signature and plaintext are both in the same blob you'll need to separate it per whatever file format you're using.

No luck. I finally resorted to openssl_pkcs7_sign which outputs a S/MIME compatible message, which I can handle in Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM