[PHP]MD5를 이용한 암호화/복호화

01 14, 2007 01:38

<?php

 
function bytexor($a,$b,$l
)
  {
  
$c=""
;
   for(
$i=0;$i<$l;$i
++) {
    
$c.=$a{$i}^$b{$i
};
   }
   return(
$c
);
  }

  function
binmd5($val
)
  {
   return(
pack("H*",md5($val
)));
  }

  function
decrypt_md5($msg,$heslo
)
  {
  
$key=$heslo;$sifra=""
;
  
$key1=binmd5($key
);
   while(
$msg
) {
    
$m=substr($msg,0,16
);
    
$msg=substr($msg,16
);
    
$sifra.=$m=bytexor($m,$key1,16
);
    
$key1=binmd5($key.$key1.$m
);
   }
   echo
"\n"
;
   return(
$sifra
);
  }

  function
crypt_md5($msg,$heslo
)
  {
  
$key=$heslo;$sifra=""
;
  
$key1=binmd5($key
);
   while(
$msg
) {
    
$m=substr($msg,0,16
);
    
$msg=substr($msg,16
);
    
$sifra.=bytexor($m,$key1,16
);
    
$key1=binmd5($key.$key1.$m
);
   }
   echo
"\n"
;
   return(
$sifra
);
  }

// Example of usage...

$message =
"This is a very long message, but it is very secret and important
and we need to keep the contents hidden from nasty people who might want to steal it."
;

$key = "secret key"
;

$crypted = crypt_md5($message, $key
);
echo
"Encoded = $crypted<BR>";
// returns

$uncrypted = decrypt_md5($crypted, $key);
echo
"Unencoded = $uncrypted";
// returns This is a very long message (etc)

?>



http://kr.php.net/manual/kr/function.md5.php

브니 Programs/Web Programs

01 14, 2007 01:38 01 14, 2007 01:38
Trackback Address:http://limcom.co.kr/blog/trackback/6
[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다