當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TCPDF_STATIC::_md5_16方法代碼示例

本文整理匯總了PHP中TCPDF_STATIC::_md5_16方法的典型用法代碼示例。如果您正苦於以下問題:PHP TCPDF_STATIC::_md5_16方法的具體用法?PHP TCPDF_STATIC::_md5_16怎麽用?PHP TCPDF_STATIC::_md5_16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TCPDF_STATIC的用法示例。


在下文中一共展示了TCPDF_STATIC::_md5_16方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _generateencryptionkey

 /**
  * Compute encryption key
  * @protected
  * @since 2.0.000 (2008-01-02)
  * @author Nicola Asuni
  */
 protected function _generateencryptionkey()
 {
     $keybytelen = $this->encryptdata['Length'] / 8;
     if (!$this->encryptdata['pubkey']) {
         // standard mode
         if ($this->encryptdata['mode'] == 3) {
             // AES-256
             // generate 256 bit random key
             $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
             // truncate passwords
             $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
             $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
             // Compute U value
             $this->encryptdata['U'] = $this->_Uvalue();
             // Compute UE value
             $this->encryptdata['UE'] = $this->_UEvalue();
             // Compute O value
             $this->encryptdata['O'] = $this->_Ovalue();
             // Compute OE value
             $this->encryptdata['OE'] = $this->_OEvalue();
             // Compute P value
             $this->encryptdata['P'] = $this->encryptdata['protection'];
             // Computing the encryption dictionary's Perms (permissions) value
             $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
             // bytes 0-3
             $perms .= chr(255) . chr(255) . chr(255) . chr(255);
             // bytes 4-7
             if (isset($this->encryptdata['CF']['EncryptMetadata']) and !$this->encryptdata['CF']['EncryptMetadata']) {
                 // byte 8
                 $perms .= 'F';
             } else {
                 $perms .= 'T';
             }
             $perms .= 'adb';
             // bytes 9-11
             $perms .= 'nick';
             // bytes 12-15
             $iv = str_repeat("", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
             $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
         } else {
             // RC4-40, RC4-128, AES-128
             // Pad passwords
             $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'] . TCPDF_STATIC::$enc_padding, 0, 32);
             $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'] . TCPDF_STATIC::$enc_padding, 0, 32);
             // Compute O value
             $this->encryptdata['O'] = $this->_Ovalue();
             // get default permissions (reverse byte order)
             $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
             // Compute encryption key
             $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'] . $this->encryptdata['O'] . $permissions . $this->encryptdata['fileid']);
             if ($this->encryptdata['mode'] > 0) {
                 for ($i = 0; $i < 50; ++$i) {
                     $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
                 }
             }
             $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
             // Compute U value
             $this->encryptdata['U'] = $this->_Uvalue();
             // Compute P value
             $this->encryptdata['P'] = $this->encryptdata['protection'];
         }
     } else {
         // Public-Key mode
         // random 20-byte seed
         $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
         $recipient_bytes = '';
         foreach ($this->encryptdata['pubkeys'] as $pubkey) {
             // for each public certificate
             if (isset($pubkey['p'])) {
                 $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
             } else {
                 $pkprotection = $this->encryptdata['protection'];
             }
             // get default permissions (reverse byte order)
             $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
             // envelope data
             $envelope = $seed . $pkpermissions;
             // write the envelope data to a temporary file
             $tempkeyfile = TCPDF_STATIC::getObjFilename('tmpkey');
             $f = fopen($tempkeyfile, 'wb');
             if (!$f) {
                 $this->Error('Unable to create temporary key file: ' . $tempkeyfile);
             }
             $envelope_length = strlen($envelope);
             fwrite($f, $envelope, $envelope_length);
             fclose($f);
             $tempencfile = TCPDF_STATIC::getObjFilename('tmpenc');
             if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
                 $this->Error('Unable to encrypt the file: ' . $tempkeyfile);
             }
             unlink($tempkeyfile);
             // read encryption signature
             $signature = file_get_contents($tempencfile, false, null, $envelope_length);
             unlink($tempencfile);
//.........這裏部分代碼省略.........
開發者ID:TheTypoMaster,項目名稱:myapps,代碼行數:101,代碼來源:tcpdf.php


注:本文中的TCPDF_STATIC::_md5_16方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。