No, at least it was designed so you can’t reverse it. However, HMAC is not intended for password, so the only way we have to recover the value can be a little faster.
HMAC is a Keyed Hash, it can be used for message authentication (MAC) and can also be used for key creation (KDF). Its use is neither, since it is using a password, and not a key, for this purpose there is PBKDF2, which can use HMAC internally.
The only way to reverse this value is just an exhaustive search, try all possible attempts, this can be done using Hashcat. But this is not so fast, especially if there are many passwords, using 8x GTX 1080 Ti this will make 4.300.000 attempts per second on average.
But if your intention is to "register in the encryption I use", you can simply register the hash and signal that that user is using an old password.
For example, if you use the hash_hmac
and now wants to change to argon2id
, you currently have something like:
Usuario | Senha | Salt
Inkeliz 0x00..00 0xFF...FF
Then just hash the hash:
Senha = argon2i(senha = 0x00..00, salt = 0xAF...AF)
So, supposing that Senha
returned 0xAA...AA
just use it and create a signage:
Usuario | Senha | Salt | SaltAntigo
Inkeliz 0xAA..AA 0xAF...AF 0xFF...FF
The SaltAntigo
could be Boolean (true/false), for example EstaUsandoSenhaAntiga?
. But, we can also use it to store the old salt, if it is null will indicate that it does not use the old. If you intend to keep the same salt then could use a Boolean even. ;)
So if another user signs up recently:
Usuario | Senha | Salt | SaltAntigo
Inkeliz 0xAA..AA 0xAF...AF 0xFF...FF
Novo 0xAB..AB 0xBF...BF null
That way, for example:
$senha = $_POST['senha'];
if $salt_antigo !== null {
$senha = hmac($senha, $salt_antigo)
}
$senha = argon2id($senha, $salt)
//...
// Se tudo estiver certo e temos a senha dele,
// podemos atualizar para usar diretamente o novo algorítimo:
$nova_senha = argon2id($_POST['senha'], $novo_salt)
query("UPDATE contas SET Senha = $nova_senha, Salt = $novo_salt, SaltAntigo = null")
This way everyone uses the new algorithm, those who use the old will update to the new, as they enter the site. ;)
You need to see if the "new encryption you use" is good, first of all (nothing homemade, except if you’re part of a great team of cryptographers) - I mentioned this, because as you said in reverse, I hope your solution doesn’t have it.
– Bacco
I think this reading might be interesting: How to hash passwords securely
– Bacco
Actually the one I’m going to use is php’s crypt() function and a salt that comes from a server in the US when it comes to creating the user. I can’t change the encryption method. I’ve never used it that way.
– Willian Coqueiro