1<?php 2 3namespace Mpdf\Pdf\Protection; 4 5class UniqidGenerator 6{ 7 8 public function __construct() 9 { 10 if (!function_exists('random_int') || !function_exists('random_bytes')) { 11 throw new \Mpdf\MpdfException( 12 'Unable to set PDF file protection, CSPRNG Functions are not available. ' 13 . 'Use paragonie/random_compat polyfill or upgrade to PHP 7.' 14 ); 15 } 16 } 17 18 /** 19 * @return string 20 */ 21 public function generate() 22 { 23 $chars = 'ABCDEF1234567890'; 24 $id = ''; 25 26 for ($i = 0; $i < 32; $i++) { 27 $id .= $chars[random_int(0, 15)]; 28 } 29 30 return md5($id); 31 } 32} 33