1

I am using phpseclib implementation AES and HMAC. But I dont know the best way to create random keys for these. What is the best way to do? Is there any built in function in phpseclib to create keys of the preferred length?

2

See the "Generating Keys" section of the Encryption documentation.

It suggests using the following code to generate a random key:

<?php
$key = \phpSec\Crypt\Rand::bytes(32);

For the sourceforge project, it appears that if you want a password-derived key, then you can use ->setPassword() on the Crypt_AES object. However, the only generation of random data that I could find is the generation of a random number. That is done through the crypt_random function. I would suggest just taking the necessary functions out of the other phpSecLib. As it is MIT-licensed, this shouldn't be a problem from a license point of view.

| improve this answer | |
1

I woulds suggest using crypt_random_string. It's not in the 0.3.1 release but it is in the latest Git version.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.