Monday, August 8, 2016

Test Enkripsi & Dekripsi PHP - Date juga.. :D

class hisoka date kyk gini :
<?php

class hisokaDate
{
    public static function udate($format = 'u', $utimestamp = null) {
        if (is_null($utimestamp))
            $utimestamp = microtime(true);

        $timestamp = floor($utimestamp);
        $milliseconds = round(($utimestamp - $timestamp) * 1000000);

        return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
    }

}

?>

Engkeripsina kek gini :
<?php
require_once('hisokadate.php');// '/hisokaDate';


$date = new DateTime(date('Y-M-H-s'));
$hisokadet = hisokaDate::udate('Y-m-d H:i:s.u T');
echo 'DateTime::format :'.$date->format('Y-m-d H:i:s:u').'<br/>';
echo 'date : '.date('s').'<br/>';
echo 'mydate : '.$hisokadet.'<br/>';
echo '========================================================<br/>';
echo 'Maenan Engkripts Broo.. :D'.' : <br/>';
echo 'SHA-512 : '.crypt($hisokadet,$hisokadet).'<br/>';
echo 'password_hash : '.password_hash($hisokadet,PASSWORD_BCRYPT,['cost'=>12]).'<br/>';
//echo 'bcrypt : '.bcrypt($hisokadet);

$key = 'SuperSecretKeyhu';
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $hisokadet, MCRYPT_MODE_ECB);
$plaintext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $encrypted, MCRYPT_MODE_ECB);
echo 'mycrypt_encrypt : '.$encrypted.'<br/>';
echo 'mycrypt_decrypt : '.$plaintext.'<br/>';

//================================================================
//Open SSL
//Encryption:
$textToEncrypt = "My Text to Encrypt";
$encryptionMethod = "AES-256-CBC";
$secretHash = "encryptionhash";
$iv = mcrypt_create_iv(16, MCRYPT_RAND);
$encryptedText = openssl_encrypt($hisokadet,$encryptionMethod,$secretHash, 0, $iv);

//Decryption:
$decryptedText = openssl_decrypt($encryptedText, $encryptionMethod, $secretHash, 0, $iv);
echo 'Open SSL Encrypt : '.$encryptedText.'<br/>';
echo 'Open SSL Decrypt : '.$decryptedText.'<br/>';

//=================================================================
?>

Hasil :


No comments:

Post a Comment