I have some information represented by 2025 bits. For caching purposes i need to create a unique filename ( not too long of course so fs will handle this ) which will represent these bits. Every set of bits should have unique filename.
Is md5 suitable for this ? If not , what should i use ?
Check out uniqid()
. If you are ultra paranoid, put the filename generation in a loop where you check to see if it exists or not.
$prefix = hash('sha256', $bits) . '-';
$filename = uniqid($prefix, true);
This creates a SHA-256 hash of the bits as the prefix to the file, and uses uniqid
to create a unique file name with the prefix of the file being the hash of the bits followed by a -
.
This should generate a unique filename that you can identify by hashing the bits.
You can use a Base64 encoding of the bits. This will guarantee uniqueness of names.