/** * Sign a request * * @param array $params * @param null|string $method * @param null|string $url * @return string */ public function sign(array $params, $method = null, $url = null) { $rsa = new Zend_Crypt_Rsa(); $rsa->setHashAlgorithm($this->_hashAlgorithm); $sign = $rsa->sign($this->_getBaseSignatureString($params, $method, $url), $this->_key, Zend_Crypt_Rsa::BASE64); return $sign; }
public function testConstructorLoadsPassphrasedKeys() { $rsa = new Zend_Crypt_Rsa(); $config = array('privateKeyBits' => 512, 'passPhrase' => '0987654321'); $keys = $rsa->generateKeys($config); try { $rsa = new Zend_Crypt_Rsa(array('passPhrase' => '0987654321', 'pemString' => $keys->privateKey->toString())); } catch (Zend_Crypt_Exception $e) { $this->fail('Passphrase loading failed of a private key'); } }
/** * @group ZF-8846 */ public function testLoadsPublicKeyFromPEMWithoutPrivateKeyAndThrowsNoException() { $rsa = new Zend_Crypt_Rsa(); $rsa->setPemString($this->_testPemStringPublic); }
private function _newkeyDecrypt($licensekey, $extensionName, $domain) { if (strlen($licensekey) < 68) { return false; } $crc32Pos = abs(crc32(substr($licensekey, 0, 10) . $extensionName) & 0x7fffffff % 49) + 10; $crc32 = substr($licensekey, $crc32Pos, 8); $key = substr($licensekey, 0, $crc32Pos) . substr($licensekey, $crc32Pos + 11); try { $rsa = new Zend_Crypt_Rsa(); $publicKey = new Zend_Crypt_Rsa_Key_Public($this->_publicKey); while (strlen($key) % 4) { $key .= '='; } $licenseString = $rsa->decrypt(base64_decode($key), $publicKey); if (!$licenseString) { return false; } if (substr($licenseString, 0, 3) != substr($licensekey, $crc32Pos + 8, 3)) { return false; } $type = substr($licenseString, 0, 1); $expiredTime = hexdec(substr($licenseString, 1, 2)); $extensionHash = substr($licenseString, 3, 8); if ($extensionHash != hash('crc32', $extensionName)) { return false; } $licenseDomain = trim(substr($licenseString, 15)); if (hash('crc32', substr($licensekey, 0, $crc32Pos) . substr($licensekey, $crc32Pos + 8) . $extensionName . $licenseDomain) != $crc32) { return false; } return new Varien_Object(array('type' => $type, 'created_date' => date('Y-m-d', hexdec(substr($licenseString, 11, 4)) * 24 * 3600), 'expired_time' => $expiredTime, 'domains' => $licenseDomain)); } catch (Exception $e) { $licenseDomain = strlen($domain) > 38 ? substr($domain, 0, 38) : $domain; if (hash('crc32', substr($licensekey, 0, $crc32Pos) . substr($licensekey, $crc32Pos + 8) . $extensionName . $licenseDomain) != $crc32) { return false; } $type = substr($licensekey, $crc32Pos + 8, 1); $expiredTime = hexdec(substr($licensekey, $crc32Pos + 9, 2)); return new Varien_Object(array('type' => $type, 'expired_time' => $expiredTime, 'domains' => $licenseDomain)); } }
<?php $rsa = new Zend_Crypt_Rsa(array('passPhrase' => 'super segreto', 'pemPath' => APPLICATION_PATH . '/privatekey.pem')); $testo = file_get_contents($filename); $firma = $rsa->sign($testo, $rsa->getPrivateKey(), Zend_Crypt_Rsa::BASE64); // Verifica la firma $verify = $rsa->verifySignature($testo, $firma, Zend_Crypt_Rsa::BASE64);