Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SignGenerator {
- // Merchant secure data - merchant key
- private $key = "1234567812345678123456781234567812345678123456781234567812345678";
- // Transaction data
- private $mid;
- private $amount;
- private $currencyAplhaCode;
- private $msTxnId;
- private $firstName;
- private $familyName;
- private $timestamp;
- // Sign config
- private $_mode = MCRYPT_MODE_CBC;
- private $_cipher;
- private $_paddingType;
- public function __construct($mid,$amount,$currency,$mstxnid,$firstname,$familyname,$timestamp){
- $this->_cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $this->_mode, '');
- $this->_paddingType = 'PKCS7';
- $this->mid = $mid;
- $this->amount = $amount;
- $this->currencyAplhaCode = $currency;
- $this->msTxnId = $mstxnid;
- $this->firstName = $firstname;
- $this->familyName = $familyname;
- $this->timestamp = $timestamp;
- $this->iv = $mid.strrev($mid);
- }
- public function getHexKey(){
- return pack("H*" , $this->key );
- }
- /*
- * WORK IN PHP OR NEWER
- public function getHexKey(){
- $hKey = "";
- for($i=0;$i<strlen($this->key);$i=$i+2){
- $hKey .= hex2bin($this->key[$i].$this->key[$i+1]);
- }
- return $hKey;
- }
- */
- public function getPlainText(){
- return $this->mid.$this->amount.$this->currencyAplhaCode.$this->msTxnId.$this->firstName.$this->familyName.$this->timestamp;
- }
- private function getData(){
- return sha1($this->getPlainText(),true);
- }
- public function signTransaction(){
- if ($this->_paddingType == 'PKCS7'){
- $data = $this->AddPadding($this->getData());
- }
- mcrypt_generic_init($this->_cipher, $this->getHexKey(), $this->iv);
- $result = mcrypt_generic($this->_cipher, $data);
- mcrypt_generic_deinit($this->_cipher);
- return strtoupper(substr(bin2hex($result),0,32));
- }
- private function AddPadding($data){
- $block = mcrypt_get_block_size('des', $this->_mode);
- $pad = $block - (strlen($data) % $block);
- $data .= str_repeat(chr($pad), $pad);
- return $data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement