Search code examples
opensslrsacryptoserviceprovider

RSACryptoServiceProvider SignHash equivalent in php / openssl?


my understanding is openssl_sign does the same as RSACryptoServiceProvider.SignData is there a openssl (or php) command the does the same as RSACryptoServiceProvider.SignHash?


Solution

  • figured it out.

    here is how i signed data in php that is compatible with DotNETs XML signature

    $private_key = "-----BEGIN PRIVATE KEY----- [private data] -----END PRIVATE KEY-----"
    
    $sig1 = "<SIGNATURE><VERSION>1.0</VERSION><DIGEST>";
    
    $sig2 = "</DIGEST><RSAKeyValue><Modulus>[private data]</Modulus><Exponent>[private data]</Exponent></RSAKeyValue></SIGNATURE>";
    
    $pkeyid = openssl_get_privatekey($private_key);
    
    openssl_sign($data, $sig,$pkeyid,OPENSSL_ALGO_SHA1);
    
    $rsasignature = $sig1.strtoupper(bin2hex($sig)).$sig2;