示例#1
0
 public function testCheckRandomNumberRepeatability()
 {
     $repeatability = \IcyApril\CryptoLib::checkRandomNumberRepeatability();
     $this->assertLessThan(1, $repeatability);
     $this->assertGreaterThan(0, $repeatability);
     $repeatability = \IcyApril\CryptoLib::checkRandomNumberRepeatability(function ($min, $max) {
         return \IcyApril\CryptoLib::randomInt($min, $max);
     });
     $this->assertLessThan(1, $repeatability);
     $this->assertGreaterThan(0, $repeatability);
     $repeatability = \IcyApril\CryptoLib::checkRandomNumberRepeatability(function ($min, $max) {
         return 5;
     });
     $this->assertEquals(1, $repeatability);
     $repeatability = \IcyApril\CryptoLib::checkRandomNumberRepeatability(function ($min, $max) {
         return microtime() . rand(0, 10000000000);
     });
     $this->assertEquals(0, $repeatability);
     $this->setExpectedException(Exception::class);
     \IcyApril\CryptoLib::checkRandomNumberRepeatability(null, 1, 100);
     $this->setExpectedException(Exception::class);
     \IcyApril\CryptoLib::checkRandomNumberRepeatability(null, 1, 1);
     $this->setExpectedException(Exception::class);
     \IcyApril\CryptoLib::checkRandomNumberRepeatability(null, 5, 1);
 }
示例#2
0
文件: demo.php 项目: gencer/CryptoLib
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * Start off my requiring the library in our demo script.
 */
require_once '../src/CryptoLib.php';
/**
 * Some nice debugging messages.
 */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
use IcyApril\CryptoLib;
/**
 * Standard procedural testers.
 */
$randomInteger = CryptoLib::randomInt(0, 255);
$randomHex = CryptoLib::randomHex(10);
$randomString = CryptoLib::randomString(10);
$repeatPercentage = CryptoLib::checkRandomNumberRepeatability();
$salt = CryptoLib::generateSalt();
$testHash = CryptoLib::hash("test");
$validateHash = CryptoLib::validateHash($testHash, "test");
$encryptedString = CryptoLib::encryptData("Test string.", "passwd");
$decryptedString = CryptoLib::decryptData($encryptedString, 'passwd');
?>

<html>
    <head>
        <title>CryptoLib Tester</title>
        <style>
            body {