+ 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.
4 Respuestas
+ 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