+ 2
SHA-512 AES
Help please!! I need to hass a password with SHA-512 AES, how can I do it using php? some example are welcome. Thanks.
5 Antwoorden
+ 10
I hope this link can help you somehow:
http://php.net/manual/en/function.hash.php
Hth, cmiiw
+ 5
Well done @Sergio, thanks for sharing this : )
+ 2
I have solve it!:
public function cryptMyPass($plaintext){
$password = '#D-$1gnD3skT0p!#';
$method = 'AES-128-CBC';
// Must be exact 32 chars (256 bit)
$password = substr(hash('sha512', $password, true), 0, 32);
// IV must be exact 16 chars (128 bit)
$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
// av3DYGLkwBsErphcyYp+imUW4QKs19hUnFyyYcXwURU=
$encrypted = base64_encode(openssl_encrypt($plaintext, $method, $password, OPENSSL_RAW_DATA, $iv));
return $encrypted;
}
+ 1
If you are using a hash function you ahould take into account that in some algorithms, different inputs may get the same output, in your case, different passwords may get hashed into the same value and be undifferentiable due to the hash function not being reversible
0
To protect a password using SHA-512, you can first turn it into a secure code using the SHA-512 method. If you also want extra protection, you can lock that code using AES encryption. In PHP, this is done using built-in functions. Just remember to safely store the secret key used for AES. I found the helpful article at:- https://certera.com/blog/sha1-vs-sha2-vs-sha256-vs-sha512-hash-algorithms-know-the-difference/. Hope it helps!