Php7 implements blowfish encryption and decryption

topic description

encryption key
2fs5uhnjcnpxcpg9
plaintext
3280VAND 99br 20120201123050
ciphertext
daa745f1901364c0bd42b9658db3db96336758cd34b2a57

sources of topics and their own ideas

related codes

/ / Please paste the code text below (do not replace the code with pictures)

$key = "2fs5uhnjcnpxcpg9";
$method = "blowfish";

$privateKey = $key;
$data = "3280:99:20120201123050";
$encrypted = openssl_encrypt($data, $method, $privateKey);
var_dump($encrypted);

what result do you expect? What is the error message actually seen?

Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in /home/wwwroot/www.testphp7.com/index.php on line 10
string(32) "2qdF8ZATZMCT14pt78C2ZAxCWc703X/r"

I hope that encryption mode ECB, does not need initialization vector through openssl_encrypt (IV,Initialization Vector), Padding mode: PKCS5Padding, I change how to modify openssl_encrypt parameters

Jan.25,2022

you can use openssl_get_cipher_methods () to get method supported by openssl , so here you
$method = 'BF-ECB'; refer to my encryption and decryption


function encrypt($data, $key)
{
    $l = strlen($key);
    if ($l < 16){
        $key = str_repeat($key, ceil(16/$l));
    }

    if ($m = strlen($data)%8){
        $data .= str_repeat("\x00",  8 - $m);
    }
    return openssl_encrypt($data, 'BF-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
}

function decrypt($data, $key)
{
    $l = strlen($key);
    if ($l < 16){
        $key = str_repeat($key, ceil(16/$l));
    }

   return  openssl_decrypt($data, 'BF-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
}



$key = '2fs5uhnjcnpxcpg9';
$data = '3280:99:20120201123050';


$c = encrypt($data, $key);
$d = decrypt($c, $key);
var_dump($c);
var_dump($d);
Menu