function aes_make_key in AES encryption 7
Same name and namespace in other branches
- 5 aes.module \aes_make_key()
- 6 aes.module \aes_make_key()
Generate a random key, containing uppercase, lowercase and digits.
Return value
string Encryption key.
1 call to aes_make_key()
- aes_get_key in ./
aes.module - Gets the current key used for the encryption system. If there's currently no key defined, this function will generate one, store it, and return it.
File
- ./
aes.module, line 410 - Main file of the AES encryption module.
Code
function aes_make_key() {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
srand();
while (TRUE) {
$key = '';
while (strlen($key) < 32) {
$key .= substr($chars, rand(0, strlen($chars)), 1);
}
// is there at least one lowercase letter?
if (!preg_match('/.*[a-z].*/', $key)) {
continue;
}
// is there at least one uppercase letter?
if (!preg_match('/.*[A-Z].*/', $key)) {
continue;
}
// is there at least one numeric?
if (!preg_match('/.*[0-9].*/', $key)) {
continue;
}
break;
}
return $key;
}