-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 を使用して同じことを行うには?

4

1 に答える 1

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
}

Javaでそれを行う方法については、わかりません:-(

于 2012-07-20T12:40:48.867 に答える