s_random() static public method

static public s_random ( $len, $textmode )
Beispiel #1
0
 /**
  * GPG Encypts a message to the provided public key
  *
  * @param GPG_Public_Key $pk
  * @param string $plaintext
  * @return string encrypted text
  */
 function encrypt($pk, $plaintext)
 {
     // normalize the public key
     $key_id = $pk->GetKeyId();
     $key_type = $pk->GetKeyType();
     $public_key = $pk->GetPublicKey();
     $session_key = GPG_Utility::s_random($this->width, 0);
     $key_id = GPG_Utility::hex2bin($key_id);
     $cp = $this->gpg_session($key_id, $key_type, $session_key, $public_key) . $this->gpg_data($session_key, $plaintext);
     $code = base64_encode($cp);
     $code = wordwrap($code, 60, "\n", 1);
     return "-----BEGIN PGP MESSAGE-----\nVersion: VerySimple PHP-GPG v" . $this->version . "\n\n" . $code . "\n=" . base64_encode(GPG_Utility::crc24($cp)) . "\n-----END PGP MESSAGE-----\n";
 }