Created
July 10, 2017 22:16
-
-
Save iam-raihan/9f9f722dbfcfe219e522b0bbe6a8b559 to your computer and use it in GitHub Desktop.
3DES cipher in ECB mode Cryptography in PHP using openssl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: Raihan | |
* Date: 10-Jul-17 | |
* Time: 4:37 AM | |
*/ | |
class CryptOpenssl{ | |
private $hash; | |
function __construct($hash){ | |
$key = md5($hash,TRUE); | |
$key .= substr($key,0,8); | |
$this->hash = $key; | |
} | |
/** | |
* @param $data | |
* @return string | |
*/ | |
public function Encrypt($data){ | |
$encData = openssl_encrypt($data, 'DES-EDE3', $this->hash, OPENSSL_RAW_DATA); | |
$encData = base64_encode($encData); | |
return $encData; | |
} | |
/** | |
* @param $data | |
* @return string | |
*/ | |
public function Decrypt($data){ | |
$data = base64_decode($data); | |
$decData = openssl_decrypt($data, 'DES-EDE3', $this->hash, OPENSSL_RAW_DATA); | |
return $decData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment