php示例代码使用mcrypt,php72中不再提供

时间:2018-05-16 13:38:04

标签: php encryption openssl mcrypt sagepay

我可以看到示例php代码使用mcrypt。

我们可以期待sagepay会重新编写php示例代码以使用open_ssl代替,或者有人已经完成了吗?

好的,由于我没有对此做出回应,我们已经尝试找出如何将mcrypt的来电替换为openssl

加密方面的原始code是:

$strIV = $strEncryptionPassword;
//** add PKCS5 padding to the text to be encypted
$strIn = addPKCS5Padding($strIn);
//** perform encryption with PHP's MCRYPT module
$strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV);

我(其中一个)尝试更换它的是:

$strIV = $strEncryptionPassword;    
$strCrypt  = openssl_encrypt($strIn,'AES-128-CBC',$strIV,$options=OPENSSL_RAW_DATA);
//** perform hex encoding and return
return "@" . bin2hex($strCrypt);

我已经尝试了OPENSSL_NO_PADDING选项以及"AES_192_CBC"以及"AES_256_CBC"

我正在比较为mcrypt加密的字符串之前和之后(并由Sagepay成功处理),但没有从openssl获取相同的加密字符串。

我很感激一些帮助。

好吧,我想我已经开始工作,虽然我不确定我必须做些什么,而不是我以前尝试过的,这里有两个功能的代码在Sagepay界面包中:

Define('SESS_CIPHER','AES-128-CBC');
function NEWencryptAndEncode($strIn) {  
global $strEncryptionType
      ,$strEncryptionPassword;
if ($strEncryptionType=="XOR") 
{
    //** XOR encryption with Base64 encoding **
    return base64Encode(simpleXor($strIn,$strEncryptionPassword));
} 
else 
{
    //** AES encryption, CBC blocking with PKCS5 padding then HEX encoding - DEFAULT **
    //** use initialization vector (IV) set from $strEncryptionPassword
$strIV = $strEncryptionPassword;    
//** add PKCS5 padding to the text to be encypted
$strIn = addPKCS5Padding($strIn);
//** perform encryption with PHP's Openssl module
    $strCrypt  = openssl_encrypt($strIn, SESS_CIPHER,$strIV,$options=OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING,$strIV);   
    //** perform hex encoding and return
    return "@" . bin2hex($strCrypt);
}}

function NEWdecodeAndDecrypt($strIn) {
global $strEncryptionPassword;
if (substr($strIn,0,1)=="@") 
{
    //** HEX decoding then AES decryption, CBC blocking with PKCS5 padding - DEFAULT ** 
    //** use initialization vector (IV) set from $strEncryptionPassword
    $strIV = $strEncryptionPassword;    
    //** remove the first char which is @ to flag this is AES encrypted
    $strIn = substr($strIn,1);      
    //** HEX decoding
    $strIn = pack('H*', $strIn);    
    //** perform decryption with PHP's MCRYPT module
    return openssl_decrypt($strIn, SESS_CIPHER,$strIV,$options=OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING,$strIV); 
} 
else 
{
    //** Base 64 decoding plus XOR decryption **
    return simpleXor(base64Decode($strIn),$strEncryptionPassword);
}}

0 个答案:

没有答案