public function validateAgainstKey($publicKey) { return Ulink_CryptoUtils::isValidRSASignature( $this->getRequest(), $this->getSignature(), $publicKey ); }
/** * @test */ public function readAndVerifyWithRealKeysKey() { // You can get a simple private/public key pair using: // openssl genrsa 512 >private_key.txt // openssl rsa -pubout <private_key.txt >public_key.txt $privKey = <<<EOD -----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z RZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQJAL151ZeMKHEU2c1qdRKS9 sTxCcc2pVwoAGVzRccNX16tfmCf8FjxuM3WmLdsPxYoHrwb1LFNxiNk1MXrxjH3R 6QIhAPB7edmcjH4bhMaJBztcbNE1VRCEi/bisAwiPPMq9/2nAiEA3lyc5+f6DEIJ h1y6BWkdVULDSM+jpi1XiV/DevxuijMCIQCAEPGqHsF+4v7Jj+3HAgh9PU6otj2n Y79nJtCYmvhoHwIgNDePaS4inApN7omp7WdXyhPZhBmulnGDYvEoGJN66d0CIHra I2SvDkQ5CmrzkW5qPaE2oO7BSqAhRZxiYpZFb5CI -----END RSA PRIVATE KEY----- EOD; $pubKey = <<<EOD -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6 zxqlVzz0wy2j4kQVUC4ZRZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQ== -----END PUBLIC KEY----- EOD; $pair = new Ulink_KeyPair($privKey, $pubKey); $myData = "foobarbaz"; $this->assertNotNull($pair->getPrivateKey()); $signatrue = Ulink_CryptoUtils::sign($myData, $pair->getPrivateKey()); $this->assertNotNull($signatrue); $this->assertTrue(Ulink_CryptoUtils::isValidRSASignature("foobarbaz", $signatrue, $pair->getPublicKey())); $this->assertFalse(Ulink_CryptoUtils::isValidRSASignature("foo", $signatrue, $pair->getPublicKey())); $sealed = Ulink_CryptoUtils::seal($myData, $pair->getPublicKey()); $opened = Ulink_CryptoUtils::unseal($sealed, $pair->getPrivateKey()); $this->assertNotEquals($myData, $sealed); $this->assertEquals($myData, $opened); }