简体   繁体   中英

Blowfish options in php

I use PHP 5.3.3 and is trying to do a blowfish encryption with these options:

The bytes of the encrypted data are hex-coded and left padded up to two characters with a zero. Blowfish ECB is used for encryption with a attached salt.

It's from an integration manual of EVO payments international (creditcard payments).

Can I use crypt()? (password_hash() is not available in 5.3)

If anyone is looking for an answer to this, here is my solution:

$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');
$iv = '12345678'; //this is ignored when using MCRYPT_MODE_ECB
mcrypt_generic_init($cipher, $blowfish_secret, $iv);
$data_blowfish = mcrypt_generic($cipher, $datastring_to_encrypt);
mcrypt_generic_deinit($cipher);
return bin2hex($data_blowfish);

It seems to work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM