Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/08/2018, 10:15
helacer
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 17 años, 11 meses
Puntos: 50
Problema con openssl Encrypt Decrypt en diferentes versiones PHP

buenas

tengo este método idéntico en 2 aplicaciones diferentes una usa php 7.0 y la otra usa php 7.2

Encrypto el dato en la aplicación A y lo envío a la aplicación B, pero cuando intento hacer el decrypt me retorna vacio o oun valor diferente, que puede estar pasando?

Gracias!

Código PHP:
function encryptDataService($strData,$mtdType=1)
    {
        
// create Default Var
        
$strReturn "";
        try {
            
// set Method Crypt
            
$method 'AES-256-ECB';
            
// set Key Crypt
            
$key    hash('sha256'$this->apiConfiguration->userConfigurationValue("key_crypt_infouser",""));
            
// validate Encrypt
            
if ($mtdType == 1) {
                
$ivSize    openssl_cipher_iv_length($method);
                
$iv        openssl_random_pseudo_bytes($ivSize);
                
$encrypted openssl_encrypt($strData$method$keyOPENSSL_RAW_DATA$iv);
                
$strReturn base64_encode($iv $encrypted);
            
// validate Decrypt
            
} else {
                
$strData   base64_decode($strData);
                
$ivSize    openssl_cipher_iv_length($method);
                
$iv        substr($strData0$ivSize);
                
$strReturn openssl_decrypt(substr($strData$ivSize), $method$keyOPENSSL_RAW_DATA$iv);
            }
        } catch (
Exception $ex) {
         
        }
        
// default Return
        
return $strReturn;
    }