*/ class GoogleGAL_Signer_PEM extends GoogleGAL_Signer_Abstract { // OpenSSL private key resource private $privateKey; // Creates a new signer from a PEM text string public function __construct($pem, $password) { if (!function_exists('openssl_x509_read')) { throw new GoogleGAL_Exception( 'The Google PHP API library needs the openssl PHP extension' ); } $this->privateKey = $pem; if (!$this->privateKey) { throw new GoogleGAL_Auth_Exception("Unable to load private key"); } } public function __destruct() { } public function sign($data) { if (version_compare(PHP_VERSION, '5.3.0') < 0) { throw new GoogleGAL_Auth_Exception( "PHP 5.3.0 or higher is required to use service accounts." ); } $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; if (!openssl_sign($data, $signature, $this->privateKey, $hash)) { throw new GoogleGAL_Auth_Exception("Unable to sign data"); } return $signature; } }