-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 回答