php7 암호화 해제 decrypt 질문입니다

php7 암호화 해제 decrypt 질문입니다

QA

php7 암호화 해제 decrypt 질문입니다

답변 5

본문


$strAESKey128 = "z#x^IcOo12345678";  // 16자리
$strAESKeyIV = str_repeat(chr(0), 16); #Same as in JAVA  16자리
if ( !function_exists( 'hex2bin' ) ) {
 function hex2bin($hexdata) {
  $bindata = '';
  for ($i = 0; $i < strlen($hexdata); $i += 2) {
   $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
  }
  return $bindata;
 }
}
function decrypt ($value)        
{                     
    global $strAESKey128, $strAESKeyIV;
    $value = hex2bin($value) ;                
    $output = mcrypt_decrypt (MCRYPT_RIJNDAEL_128, $strAESKey128, $value, MCRYPT_MODE_CBC, str_repeat(chr(0),16)) ;                
    
    $valueLen = strlen ($output) ;
    if ( $valueLen % 16 > 0 )
        $output = "";
    $padSize = ord ($output{$valueLen - 1}) ;
    if ( ($padSize < 1) or ($padSize > 16) )
        $output = "";                // Check padding.                
    for ($i = 0; $i < $padSize; $i++)
    {
        if ( ord ($output{$valueLen - $i - 1}) != $padSize )
            $output = "";
    }
    $output = substr ($output, 0, $valueLen - $padSize) ;
    return base64_decode($output);        
}

 

 

php5에서 입력받은 db를 php7으로 이전하였습니다.

데이터는 모두 encrypt로 암호화 되어있습니다

php7에서는 decrypt가 안되는데 어떻게 처리 해야할지 모르겠습니다.

구글링을 해봤지만 잘 되지 않습니다..

 

*서버는 cafe24 웹호스팅입니다.

이 질문에 댓글 쓰기 :

답변 5

php7.2 이상에서 mcrypt_encrypt , mcrypt_decrypt 함수가 제거되었습니다.

 

카페24 웹호스팅에서 위 함수를 사용하실려면 

그곳 나의 서비스관리로 들어가 변경신청에서 php버전을 7.0으로 셋팅해 사용해 보세요.

 

encrypt() 함수는 없나요?

function encrypt ($value)
{               
    global $strAESKey128, $strAESKeyIV;
    $padSize = 16 - (strlen (base64_encode($value)) % 16) ;
    $value = base64_encode($value) . str_repeat (chr ($padSize), $padSize) ;
    $output = mcrypt_encrypt (MCRYPT_RIJNDAEL_128, $strAESKey128, $value, MCRYPT_MODE_CBC, str_repeat(chr(0),16));               
    return strtoupper(bin2hex ($output)) ;       
}

이겁니다!

https://www.php.net/manual/en/function.mcrypt-encrypt.php

mcrypt_encrypt

Warning

This function has been DEPRECATED as of PHP 7.1.0 and REMOVED as of PHP 7.2.0. Relying on this function is highly discouraged.

 

php 7.2부터는 없어졌습니다.

https://gist.github.com/mailightkun/f46066e0b3601a8093aedb662c8aee79

대신 openssl_encrypt()를 추천합니다.

대신 

답변을 작성하시기 전에 로그인 해주세요.
전체 3
© SIRSOFT
현재 페이지 제일 처음으로