Browse Source

fix: unable to pass odd number to genRandomChar (#2403)

* fix: unable to pass odd number to genRandomChar
pplulee 1 year ago
parent
commit
8aba3ae1eb
1 changed files with 2 additions and 1 deletions
  1. 2 1
      src/Utils/Tools.php

+ 2 - 1
src/Utils/Tools.php

@@ -186,7 +186,8 @@ final class Tools
             $length = 2;
         }
 
-        return bin2hex(openssl_random_pseudo_bytes($length / 2));
+        $randomString = bin2hex(openssl_random_pseudo_bytes((int) ceil($length / 2)));
+        return substr($randomString, 0, $length);
     }
 
     public static function genSs2022UserPk(string $passwd, string $method): string|false