AcmePhp\Ssl\Signer\DataSigner::signData PHP Method

signData() public method

Generate a signature of the given data using a private key and an algorithm.
public signData ( string $data, PrivateKey $privateKey, integer $algorithm = OPENSSL_ALGO_SHA256 ) : string
$data string
$privateKey AcmePhp\Ssl\PrivateKey
$algorithm integer
return string
    public function signData($data, PrivateKey $privateKey, $algorithm = OPENSSL_ALGO_SHA256)
    {
        if (!openssl_sign($data, $signature, $privateKey->getResource(), $algorithm)) {
            throw new DataSigningException(sprintf('OpenSSL data signing failed with error: %s', openssl_error_string()));
        }
        return $signature;
    }

Usage Example

Example #1
0
 /**
  * Send a request encoded in the format defined by the ACME protocol.
  *
  * @param string $method
  * @param string $endpoint
  * @param array  $payload
  * @param bool   $returnJson
  *
  * @throws AcmeCoreServerException When the ACME server returns an error HTTP status code.
  * @throws AcmeCoreClientException When an error occured during response parsing.
  *
  * @return array|string Array of parsed JSON if $returnJson = true, string otherwise
  */
 public function signedRequest($method, $endpoint, array $payload = [], $returnJson = true)
 {
     $privateKey = $this->accountKeyPair->getPrivateKey();
     $parsedKey = $this->keyParser->parse($privateKey);
     $header = ['alg' => 'RS256', 'jwk' => ['kty' => 'RSA', 'n' => $this->base64Encoder->encode($parsedKey->getDetail('n')), 'e' => $this->base64Encoder->encode($parsedKey->getDetail('e'))]];
     $protected = $header;
     if ($this->lastResponse) {
         $protected['nonce'] = $this->lastResponse->getHeaderLine('Replay-Nonce');
     }
     $protected = $this->base64Encoder->encode(json_encode($protected));
     $payload = $this->base64Encoder->encode(json_encode($payload, JSON_UNESCAPED_SLASHES));
     $signature = $this->base64Encoder->encode($this->dataSigner->signData($protected . '.' . $payload, $privateKey));
     $payload = ['header' => $header, 'protected' => $protected, 'payload' => $payload, 'signature' => $signature];
     return $this->unsignedRequest($method, $endpoint, $payload, $returnJson);
 }
All Usage Examples Of AcmePhp\Ssl\Signer\DataSigner::signData
DataSigner