php mcrypt equivalent for sagepay on a windows ser

2019-06-05 08:08发布

Our company primarily used vbscript until fairly recently, when we started changing to PHP. Upon trying to integrate a SagePay form kit into one of our projects I came across this obstacle.

We are on a windows 2008 server, and this cannot be changed. The server does not contain the mcrypt library and our server host will not install it due to it being a shared platform.

The problematic line comes from a SagePay form kit that you use to pay for things with SagePay. Hopefully some of you will be familiar with these.

The line in question is:

//** perform encryption with PHP's MCRYPT module
$strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV);

This is part of a larger encrytion function as follows:

//** Wrapper function do encrypt an encode based on strEncryptionType setting **
function encryptAndEncode($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 MCRYPT module
        $strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV);

        //** perform hex encoding and return
        return "@" . bin2hex($strCrypt);
    }
}

Does anyone know how I may possibly be able to bypass this problem, or an equivalent library that I may be able to implement in its place? Any pointers, tips or points in the correct direction would be most appreciated.

EDIT Ok so after researching it more, as I understand it, I just need a 128 bit AES Encryption function, without the use of mcrypt.

2条回答
Emotional °昔
2楼-- · 2019-06-05 08:19

An alternative to the native extension is phpseclib

http://phpseclib.sourceforge.net/

查看更多
祖国的老花朵
3楼-- · 2019-06-05 08:22

There are plenty of alternatives, the lack of support/willingness from your hosing provider would be the sticky point.

If you were on your own VPS/In a position to go down a new route. I'd recommend OpenSSL; http://www.openssl.org/ - Since you're on windows maybe check out http://slproweb.com/products/Win32OpenSSL.html

Have you checked through phpinfo()to see what is available to you?

There is also PCrypt; http://www.phpclasses.org/package/1610-PHP-Symetric-encryption-of-data-using-only-PHP-code.html

查看更多
登录 后发表回答