Neos\Flow\Security\Cryptography\RsaWalletServicePhp::sign PHP Method

sign() public method

Signs the given plaintext with the private key identified by the given fingerprint
public sign ( string $plaintext, string $fingerprint ) : string
$plaintext string The plaintext to sign
$fingerprint string The fingerprint to identify the private key (RSA public key fingerprint)
return string The signature of the given plaintext
    public function sign($plaintext, $fingerprint)
    {
        if ($fingerprint === null || !isset($this->keys[$fingerprint])) {
            throw new InvalidKeyPairIdException('Invalid keypair fingerprint given', 1299095799);
        }
        $signature = '';
        openssl_sign($plaintext, $signature, $this->keys[$fingerprint]['privateKey']->getKeyString());
        return $signature;
    }

Usage Example

 /**
  * @test
  */
 public function signAndVerifySignatureBasicallyWorks()
 {
     $plaintext = 'trustworthy data!';
     $signature = $this->rsaWalletService->sign($plaintext, $this->keyPairUuid);
     $this->assertTrue($this->rsaWalletService->verifySignature($plaintext, $signature, $this->keyPairUuid));
     $this->assertFalse($this->rsaWalletService->verifySignature('modified data!', $signature, $this->keyPairUuid));
 }