Hola amigos! Tiempo que no pasaba por aquí... Me gustaría saber su opinión sobre el resultado de este cifrado y que tan efectivo lo ven. Gracias de ante mano
<?php
function generarCodigo($longitud) {
$key = '';
$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$max = strlen($pattern)-1;
for($i=0;$i < $longitud;$i++) $key .= $pattern{mt_rand(0,$max)};
return $key;
}
$plaintext = 'Hola Mundo';
$password = generarCodigo(32);
$method = 'aes-256-cbc';
$key = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
//echo "Key:" . $key . "<br>";
$iv = rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9);
$encrypted = base64_encode(openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv));
$decrypted = openssl_decrypt(base64_decode($encrypted), $method, $key, OPENSSL_RAW_DATA, $iv);
echo 'decrypted to: ' . $decrypted . "<br>";
echo $encrypted ."<br>";