이전 목록 다음
채택완료

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

2021-06-20 (일) 03:41:01 1,923
Copy
$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개 / 댓글 1개

채택된 답변
+20 포인트

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

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

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

2021-06-20 (일) 10:35:32

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()를 추천합니다.

대신 

2021-06-20 (일) 08:20:07

php5 상에서 복호화 ==> 텍스트나 디비에 저장

  ==>    저장된 암호를 php7 가능 함호화 함수로 암호화 

하는 것도 한 가지 방법 같습니다.

2021-06-20 (일) 05:07:42

encrypt() 함수는 없나요?

답변에 대한 댓글 1개

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)) ;
}

이겁니다!

답변을 작성하려면 로그인이 필요합니다.