Google_PemVerifier

Verifies signatures using PEM encoded certificates.

Defined (1)

The class is defined in the following location(s).

/google-api-php-client/api-code/auth/Google_PemVerifier.php  
  1. class Google_PemVerifier extends Google_Verifier { 
  2. private $publicKey; 
  3.  
  4. /** 
  5. * Constructs a verifier from the supplied PEM-encoded certificate. 
  6. * $pem: a PEM encoded certificate (not a file). 
  7. * @param $pem 
  8. * @throws Google_AuthException 
  9. * @throws Google_Exception 
  10. */ 
  11. function __construct($pem) { 
  12. if (!function_exists('openssl_x509_read')) { 
  13. throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); 
  14. $this->publicKey = openssl_x509_read($pem); 
  15. if (!$this->publicKey) { 
  16. throw new Google_AuthException("Unable to parse PEM: $pem"); 
  17.  
  18. function __destruct() { 
  19. if ($this->publicKey) { 
  20. openssl_x509_free($this->publicKey); 
  21.  
  22. /** 
  23. * Verifies the signature on data. 
  24. * Returns true if the signature is valid, false otherwise. 
  25. * @param $data 
  26. * @param $signature 
  27. * @throws Google_AuthException 
  28. * @return bool 
  29. */ 
  30. function verify($data, $signature) { 
  31. $status = openssl_verify($data, $signature, $this->publicKey, "sha256"); 
  32. if ($status === -1) { 
  33. throw new Google_AuthException('Signature verification error: ' . openssl_error_string()); 
  34. return $status === 1;