当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt_DES::encrypt方法代码示例

本文整理汇总了PHP中Crypt_DES::encrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_DES::encrypt方法的具体用法?PHP Crypt_DES::encrypt怎么用?PHP Crypt_DES::encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt_DES的用法示例。


在下文中一共展示了Crypt_DES::encrypt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Crypto

 public static function Crypto($text, $cipher, $key, $isEncrypt)
 {
     switch ($cipher) {
         case 'DES':
             $crypt = new Crypt_DES(CRYPT_DES_MODE_CBC);
             $crypt->setKey($key);
             $crypt->setIV($key);
             if ($isEncrypt) {
                 return strtoupper(bin2hex($crypt->encrypt($text)));
             } else {
                 return $crypt->decrypt(CryptoUtil::hex2bin($text));
             }
             break;
         case 'AES-256':
             $crypt = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_ECB);
             $crypt->setKey($key);
             if ($isEncrypt) {
                 return strtoupper(bin2hex($crypt->encrypt($text)));
             } else {
                 return $crypt->decrypt(CryptoUtil::hex2bin($text));
             }
             break;
         default:
             break;
     }
     return "ERROR";
 }
开发者ID:jemmy655,项目名称:OpenCart-API-service-by-Kancart.com-Mobile,代码行数:27,代码来源:CryptoUtil.php

示例2: idtagDesEncode

 public static function idtagDesEncode($key, $text)
 {
     $crypt_des = new Crypt_DES();
     $crypt_des->setKey($key);
     $crypt_des->setIV($key);
     $encrypted = $crypt_des->encrypt($text);
     return base64_encode($encrypted);
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:8,代码来源:MSecret.php

示例3: parse_result

function parse_result($smsbody)
{
    global $post_data;
    //var_dump( $post_data);
    $post_data["smsbody"] = $smsbody;
    //echo $post_data;
    $temp_data = json_encode($post_data);
    //采用json的方式传递数据
    $KEY = 'e55a65-@';
    $crypt = new Crypt_DES(CRYPT_DES_MODE_ECB);
    $crypt->setKey($KEY);
    $temp_data = $crypt->encrypt($temp_data);
    // 加密后的数据
    $data_md5 = strtolower(md5($temp_data));
    $token = md5(substr($data_md5, 0, 16) . "_360mobile_" . substr($data_md5, 16));
    //产生token传送,用来接受方检验数据的合法性
    $url = 'http://w-sweng2.mobi.zzbc.qihoo.net:8810/parsesms_v2/index.php?token=' . $token;
    $result = curl_http($url, $temp_data);
    //传递的是加密后的数据
    //echo $result;
    return $result;
}
开发者ID:disibutatian,项目名称:parsesms,代码行数:22,代码来源:test.php

示例4: encrypt

 /**
  * Encrypts a message.
  *
  * @see Crypt_Base::encrypt()
  * @access public
  * @param String $plaintext
  * @return String $cipertext
  */
 function encrypt($plaintext)
 {
     // parent::en/decrypt() is able to do all the work for all modes and keylengths,
     // except for: CRYPT_DES_MODE_3CBC (inner chaining CBC) with a key > 64bits
     // if the key is smaller then 8, do what we'd normally do
     if ($this->mode_3cbc && strlen($this->key) > 8) {
         return $this->des[2]->encrypt($this->des[1]->decrypt($this->des[0]->encrypt($this->_pad($plaintext))));
     }
     return parent::encrypt($plaintext);
 }
开发者ID:anthrotech,项目名称:laravel_sample,代码行数:18,代码来源:TripleDES.php

示例5: count

 /**
  * Convert a private key to the appropriate format.
  *
  * @access private
  * @see setPrivateKeyFormat()
  * @param String $RSAPrivateKey
  * @return String
  */
 function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
 {
     $signed = $this->privateKeyFormat != CRYPT_RSA_PRIVATE_FORMAT_XML;
     $num_primes = count($primes);
     $raw = array('version' => $num_primes == 2 ? chr(0) : chr(1), 'modulus' => $n->toBytes($signed), 'publicExponent' => $e->toBytes($signed), 'privateExponent' => $d->toBytes($signed), 'prime1' => $primes[1]->toBytes($signed), 'prime2' => $primes[2]->toBytes($signed), 'exponent1' => $exponents[1]->toBytes($signed), 'exponent2' => $exponents[2]->toBytes($signed), 'coefficient' => $coefficients[2]->toBytes($signed));
     // if the format in question does not support multi-prime rsa and multi-prime rsa was used,
     // call _convertPublicKey() instead.
     switch ($this->privateKeyFormat) {
         case CRYPT_RSA_PRIVATE_FORMAT_XML:
             if ($num_primes != 2) {
                 return false;
             }
             return "<RSAKeyValue>\r\n" . '  <Modulus>' . base64_encode($raw['modulus']) . "</Modulus>\r\n" . '  <Exponent>' . base64_encode($raw['publicExponent']) . "</Exponent>\r\n" . '  <P>' . base64_encode($raw['prime1']) . "</P>\r\n" . '  <Q>' . base64_encode($raw['prime2']) . "</Q>\r\n" . '  <DP>' . base64_encode($raw['exponent1']) . "</DP>\r\n" . '  <DQ>' . base64_encode($raw['exponent2']) . "</DQ>\r\n" . '  <InverseQ>' . base64_encode($raw['coefficient']) . "</InverseQ>\r\n" . '  <D>' . base64_encode($raw['privateExponent']) . "</D>\r\n" . '</RSAKeyValue>';
             break;
         case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
             if ($num_primes != 2) {
                 return false;
             }
             $key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
             $encryption = !empty($this->password) || is_string($this->password) ? 'aes256-cbc' : 'none';
             $key .= $encryption;
             $key .= "\r\nComment: " . $this->comment . "\r\n";
             $public = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']);
             $source = pack('Na*Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption, strlen($this->comment), $this->comment, strlen($public), $public);
             $public = base64_encode($public);
             $key .= "Public-Lines: " . (strlen($public) + 63 >> 6) . "\r\n";
             $key .= chunk_split($public, 64);
             $private = pack('Na*Na*Na*Na*', strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'], strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']);
             if (empty($this->password) && !is_string($this->password)) {
                 $source .= pack('Na*', strlen($private), $private);
                 $hashkey = 'putty-private-key-file-mac-key';
             } else {
                 $private .= crypt_random_string(16 - (strlen($private) & 15));
                 $source .= pack('Na*', strlen($private), $private);
                 if (!class_exists('Crypt_AES')) {
                     include_once 'Crypt/AES.php';
                 }
                 $sequence = 0;
                 $symkey = '';
                 while (strlen($symkey) < 32) {
                     $temp = pack('Na*', $sequence++, $this->password);
                     $symkey .= pack('H*', sha1($temp));
                 }
                 $symkey = substr($symkey, 0, 32);
                 $crypto = new Crypt_AES();
                 $crypto->setKey($symkey);
                 $crypto->disablePadding();
                 $private = $crypto->encrypt($private);
                 $hashkey = 'putty-private-key-file-mac-key' . $this->password;
             }
             $private = base64_encode($private);
             $key .= 'Private-Lines: ' . (strlen($private) + 63 >> 6) . "\r\n";
             $key .= chunk_split($private, 64);
             if (!class_exists('Crypt_Hash')) {
                 include_once 'Crypt/Hash.php';
             }
             $hash = new Crypt_Hash('sha1');
             $hash->setKey(pack('H*', sha1($hashkey)));
             $key .= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";
             return $key;
         default:
             // eg. CRYPT_RSA_PRIVATE_FORMAT_PKCS1
             $components = array();
             foreach ($raw as $name => $value) {
                 $components[$name] = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($value)), $value);
             }
             $RSAPrivateKey = implode('', $components);
             if ($num_primes > 2) {
                 $OtherPrimeInfos = '';
                 for ($i = 3; $i <= $num_primes; $i++) {
                     // OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo
                     //
                     // OtherPrimeInfo ::= SEQUENCE {
                     //     prime             INTEGER,  -- ri
                     //     exponent          INTEGER,  -- di
                     //     coefficient       INTEGER   -- ti
                     // }
                     $OtherPrimeInfo = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true));
                     $OtherPrimeInfo .= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true));
                     $OtherPrimeInfo .= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true));
                     $OtherPrimeInfos .= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo);
                 }
                 $RSAPrivateKey .= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos);
             }
             $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
             if ($this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_PKCS8) {
                 $rsaOID = pack('H*', '300d06092a864886f70d0101010500');
                 // hex version of MA0GCSqGSIb3DQEBAQUA
                 $RSAPrivateKey = pack('Ca*a*Ca*a*', CRYPT_RSA_ASN1_INTEGER, "", $rsaOID, 4, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
                 $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
                 if (!empty($this->password) || is_string($this->password)) {
                     $salt = crypt_random_string(8);
//.........这里部分代码省略.........
开发者ID:jneivil,项目名称:api,代码行数:101,代码来源:RSA.php

示例6: die

if (isset($_POST['tkljuc'])) {
    file_put_contents('tajni_kljuc.txt', '');
    $data = $_POST['tkljuc'];
    $ret = file_put_contents('tajni_kljuc.txt', $data, FILE_APPEND | LOCK_EX);
    if ($ret === false) {
        die('Neuspješna pohrana u datoteku');
    } else {
        echo "U datoteku je pohranjeno: " . $ret . " bajtova";
    }
}
if (isset($_POST['kriptiraj'])) {
    file_put_contents('kriptirani_tekst.txt', '');
    $tajni_kljuc = file_get_contents('./tajni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $cipher->setKey($tajni_kljuc);
    $cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
    $kriptirani_tekst = base64_encode($cipher->encrypt($cisti_tekst));
    $ret = file_put_contents('kriptirani_tekst.txt', $kriptirani_tekst, FILE_APPEND | LOCK_EX);
    if ($ret === false) {
        die('Neuspješna pohrana u datoteku');
    } else {
        echo "U datoteku je pohranjeno: " . $ret . " bajtova";
    }
}
if (isset($_POST['dekriptiraj'])) {
    $tajni_kljuc = file_get_contents('./tajni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $cipher->setKey($tajni_kljuc);
    $kriptirani_tekst = file_get_contents('./kriptirani_tekst.txt', FILE_USE_INCLUDE_PATH);
    $dekriptirani_tekst = $cipher->decrypt(base64_decode($kriptirani_tekst));
}
?>
开发者ID:jtrupina,项目名称:os2-project,代码行数:30,代码来源:simetricni.php

示例7: encrypt

 /**
  * 對稱加密
  */
 public static function encrypt($text, $key = KEY)
 {
     $crypt_des = new Crypt_DES();
     $crypt_des->setKey($key);
     $crypt_des->setIV($key);
     return base64_encode($crypt_des->encrypt($text));
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:10,代码来源:MiniUtil.php


注:本文中的Crypt_DES::encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。