Initial Commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class App_Service_RsaCryptor
|
||||
{
|
||||
const RSA_PATH = APPLICATION_PATH . '/../rsa/';
|
||||
const PASS_PHRASE = 'bX3rQ5vCr8CChT';
|
||||
|
||||
const RSA_OBJECT_REGISTRY_NAME = 'RSA_OBJECT';
|
||||
|
||||
protected $_cryptor;
|
||||
|
||||
const RSA_KEY_OPTIONS = array(
|
||||
'pemPath' => self::RSA_PATH."private_key.pem",
|
||||
'certificatePath' => self::RSA_PATH. 'public_key.pub',
|
||||
'passPhrase' => self::PASS_PHRASE,
|
||||
'hashAlgorithm' => OPENSSL_ALGO_SHA1
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
if(Zend_Registry::isRegistered(self::RSA_OBJECT_REGISTRY_NAME)){
|
||||
$this->_cryptor = Zend_Registry::get(self::RSA_OBJECT_REGISTRY_NAME);
|
||||
}else{
|
||||
$this->_cryptor = new Zend_Crypt_Rsa(self::RSA_KEY_OPTIONS);
|
||||
Zend_Registry::set(self::RSA_OBJECT_REGISTRY_NAME, $this->_cryptor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getPrivateKey(){
|
||||
return new Zend_Crypt_Rsa_Key_Private($this->_cryptor->getPemString(), self::RSA_KEY_OPTIONS['passPhrase']);
|
||||
}
|
||||
|
||||
public function getPublicKey(){
|
||||
return new Zend_Crypt_Rsa_Key_Public($this->_cryptor->getCertificateString(), self::RSA_KEY_OPTIONS['passPhrase']);
|
||||
}
|
||||
|
||||
public function cripta($data){
|
||||
return $this->_cryptor->encrypt($data, $this->getPrivateKey(), 'base64');
|
||||
}
|
||||
|
||||
public function decripta($data){
|
||||
return $this->_cryptor->decrypt($data, $this->getPublicKey(), 'base64');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user