<?php namespace App\Util;

use Illuminate\Support\Facades\Crypt;

class CryptUtil   {

    public static function generateKey($cin){
        $date = new \DateTime();
        $key=$cin.$date->getTimestamp();
        $cryptedKey=Crypt::encrypt($key);
        return $cryptedKey;
    }

    public static function isValideKey($cryptedKey){
        $key=Crypt::decrypt($cryptedKey);
        $keyTime=substr($key,8);
        $keyCin=substr($key,0,8);
        $date=new \DateTime();
        $time=$date->getTimestamp();
        if($time-$keyTime<(30*60))
            return $keyCin;
        return false;
    }


}