2012-07-20 3 views
-1
public static function getEncryptedData($value){ 
     if(!$value){return false;} 
     $text = $value; 
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); 
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); 
     $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, _PR_ACCOUNT_ACTIVATION_SECURE_KEY_, $text, MCRYPT_MODE_ECB, $iv); 
     return trim(base64_encode($crypttext)); //encode for cookie 
    } 

나는 PHP에서 위의 코드를 발견했습니다.
이해해야합니다 :
1. 무엇을하고 있습니까?
2. Java에서 Apache Shiro를 사용하여 동일한 작업을 수행하는 방법은 무엇입니까?PHP 암호화 코드 설명

+0

:-(몰라 :이 모드의 IV를 사용하지 않는 (ECB)에 대한 IV를 생성 –

답변

1
/*Sets the function with the ability to be called globally without instantiating the object. Take one value into method through classname::getEncryptedData($value)*/ 
public static function getEncryptedData($value){ 
    /*Checks to see if value is populated and an erroneous value hasn't been passed in such as null returns false if it has*/ 
    if(!$value){return false;} 
/* instantiated a local variable called text and populate it with the value $value*/ 
    $text = $value; 
/*as per the docs http://php.net/manual/en/function.mcrypt-get-iv-size.php gets the size of the iv and sets it in the var $iv_size*/ 
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); 
/*Creates an initialization vector as per http://uk3.php.net/manual/en/function.mcrypt-create-iv.php*/ 
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); 
/*Encrypt the data $text(from $value passed it) and store it in $crypttext */ 
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, _PR_ACCOUNT_ACTIVATION_SECURE_KEY_, $text, MCRYPT_MODE_ECB, $iv); 
/*return a base64 encoded string with the whitespace trimmed from front and back*/ 
    return trim(base64_encode($crypttext)); //encode for cookie 
} 

자바에서 작업을 수행하는 방법에 관해서는 나는 무엇을하고있는 것은 부분적으로 무감각이다

+0

. 다운 voting은 무엇입니까? anon downvoting은 가장 나쁜 SO 기능입니다. downvoting하는 이유에 대한 설명이 없으면 어떻게 개선 될 수 있습니까! –