GPG_Utility::crc24 PHP Method

crc24() static public method

static public crc24 ( $data )
    static function crc24($data)
    {
        $crc = 0xb704ce;
        for ($n = 0; $n < strlen($data); $n++) {
            $crc ^= (ord($data[$n]) & 0xff) << 0x10;
            for ($i = 0; $i < 8; $i++) {
                $crc <<= 1;
                if ($crc & 0x1000000) {
                    $crc ^= 0x1864cfb;
                }
            }
        }
        return chr($crc >> 0x10 & 0xff) . chr($crc >> 0x8 & 0xff) . chr($crc & 0xff);
    }

Usage Example

コード例 #1
0
ファイル: GPG.php プロジェクト: niceboy120/phreeze
 /**
  * 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";
 }