public function testEncryptionUsingPrivateKeyBase64Encryption() { $rsa = new Zend_Crypt_Rsa(array('pemString' => $this->_testPemString)); $encrypted = $rsa->encrypt('1234567890', $rsa->getPrivateKey(), Zend_Crypt_Rsa::BASE64); $this->assertEquals('1234567890', $rsa->decrypt($encrypted, $rsa->getPublicKey(), Zend_Crypt_Rsa::BASE64)); }
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)); } }