Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/zendframework/zf2 into Ib…
Browse files Browse the repository at this point in the history
…anSepa
  • Loading branch information
Mike committed Jul 31, 2012
14 parents 6893542 + b251bdd + 9ecdb37 + 1b357ee + 4a7c17e + a40cc7f + a000f96 + fef31dc + 2b50632 + e854c8c + 450528a + 01abc0c + af61218 + cbe8a27 commit a212dd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/PublicKey/Rsa.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ public function verify($data, $signature, Rsa\PublicKey $publicKey = null)
$publicKey = $this->options->getPublicKey();
}

// check if signature is encoded in Base64
$output = base64_decode($signature, true);
if (false !== $output) {
$signature = $output;
}

$result = openssl_verify(
$data,
$signature,
Expand Down Expand Up @@ -245,6 +251,12 @@ public function decrypt($data, Rsa\AbstractKey $key = null)
throw new Exception\InvalidArgumentException('No key specified for the decryption');
}

// check if data is encoded in Base64
$output = base64_decode($data, true);
if (false !== $output) {
$data = $output;
}

return $key->decrypt($data);
}

Expand Down
4 changes: 2 additions & 2 deletions test/PublicKey/RsaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function testVerifyVerifiesBinarySignaturesUsingCertificate()
public function testVerifyVerifiesBase64Signatures()
{
$signature = $this->rsaBase64Out->sign('1234567890');
$result = $this->rsaBase64Out->verify('1234567890', base64_decode($signature));
$result = $this->rsaBase64Out->verify('1234567890', $signature);

$this->assertSame(true, $result);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public function testEncryptionUsingPublicKeyBase64Encryption()
$this->assertEquals(
'1234567890',
$this->rsaBase64Out->decrypt(
base64_decode($encrypted),
$encrypted,
$this->rsaBase64Out->getOptions()->getPrivateKey()
)
);
Expand Down

0 comments on commit a212dd6

Please sign in to comment.