robrichards / xmlseclibs

A PHP library for XML Security
BSD 3-Clause "New" or "Revised" License
388 stars 181 forks source link

Cert Stream OpenSSL #184

Closed elvispdosreis closed 5 years ago

elvispdosreis commented 5 years ago

I have the certificate in OpenSSL format, how do I inject it

$signcert = {resource} resource id='15' type='OpenSSL X.509' $privkey = {resource} resource id='16' type='OpenSSL key'

<?php $pfx = file_get_contents($file); if (!openssl_pkcs12_read($pfx, $result, $password)) { throw new \Exception('Não foi possível ler o certificado .pfx'); }

$signcert = openssl_x509_read($file); $privkey = openssl_pkey_get_private($result['pkey'], $password);

$sig = new XMLSecurityDSig(); $key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'private'));

$key->loadKey($privkey, false, true); $sig->add509Cert($signcert );

robrichards commented 5 years ago

You should just be able to set it directly on the key. $key->key = $privkey For the cert, you use openssl_x509_export on the resource to get it into a compatible format to add to the signature