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


PHP Crypt_DES::setKey方法代码示例

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


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

 function getKey($astrMerchantID, $astrFileName)
 {
     $fh = fopen($astrFileName, 'r');
     $strmodulas = fgets($fh);
     $strmodulas = trim($strmodulas);
     fclose($fh);
     $lMKey = 'MTIzNjU0MTIzOTg3MTIzNA==';
     $des = new Crypt_DES(CRYPT_DES_MODE_ECB);
     $des->setKey($this->hexstr(base64_decode($lMKey)));
     $cleartext = $des->decrypt($this->hexstr($strmodulas));
     $hexkey = $this->strhex($cleartext);
     $hexkey = strlen($hexkey) <= 40 ? $hexkey : substr($hexkey, 0, 40);
     return $hexkey;
 }
开发者ID:mydos,项目名称:JBIMS-Admission,代码行数:14,代码来源:EncryptionUtil.php

示例4: 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

示例5: setKey

 /**
  * Sets the key.
  *
  * Keys can be of any length.  Triple DES, itself, can use 128-bit (eg. strlen($key) == 16) or
  * 192-bit (eg. strlen($key) == 24) keys.  This function pads and truncates $key as appropriate.
  *
  * DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
  *
  * If the key is not explicitly set, it'll be assumed to be all null bytes.
  *
  * @access public
  * @see Crypt_DES::setKey()
  * @see Crypt_Base::setKey()
  * @param String $key
  */
 function setKey($key)
 {
     $length = strlen($key);
     if ($length > 8) {
         $key = str_pad(substr($key, 0, 24), 24, chr(0));
         // if $key is between 64 and 128-bits, use the first 64-bits as the last, per this:
         // http://php.net/function.mcrypt-encrypt#47973
         //$key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24);
     } else {
         $key = str_pad($key, 8, chr(0));
     }
     parent::setKey($key);
     // And in case of CRYPT_DES_MODE_3CBC:
     // if key <= 64bits we not need the 3 $des to work,
     // because we will then act as regular DES-CBC with just a <= 64bit key.
     // So only if the key > 64bits (> 8 bytes) we will call setKey() for the 3 $des.
     if ($this->mode_3cbc && $length > 8) {
         $this->des[0]->setKey(substr($key, 0, 8));
         $this->des[1]->setKey(substr($key, 8, 8));
         $this->des[2]->setKey(substr($key, 16, 8));
     }
 }
开发者ID:anthrotech,项目名称:laravel_sample,代码行数:37,代码来源:TripleDES.php

示例6: switch

 /**
  * Break a public or private key down into its constituant components
  *
  * @access private
  * @see _convertPublicKey()
  * @see _convertPrivateKey()
  * @param String $key
  * @param Integer $type
  * @return Array
  */
 function _parseKey($key, $type)
 {
     switch ($type) {
         case CRYPT_RSA_PUBLIC_FORMAT_RAW:
             if (!is_array($key)) {
                 return false;
             }
             $components = array();
             switch (true) {
                 case isset($key['e']):
                     $components['publicExponent'] = $key['e']->copy();
                     break;
                 case isset($key['exponent']):
                     $components['publicExponent'] = $key['exponent']->copy();
                     break;
                 case isset($key['publicExponent']):
                     $components['publicExponent'] = $key['publicExponent']->copy();
                     break;
                 case isset($key[0]):
                     $components['publicExponent'] = $key[0]->copy();
             }
             switch (true) {
                 case isset($key['n']):
                     $components['modulus'] = $key['n']->copy();
                     break;
                 case isset($key['modulo']):
                     $components['modulus'] = $key['modulo']->copy();
                     break;
                 case isset($key['modulus']):
                     $components['modulus'] = $key['modulus']->copy();
                     break;
                 case isset($key[1]):
                     $components['modulus'] = $key[1]->copy();
             }
             return $components;
         case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
         case CRYPT_RSA_PUBLIC_FORMAT_PKCS1:
             /* Although PKCS#1 proposes a format that public and private keys can use, encrypting them is
                                "outside the scope" of PKCS#1.  PKCS#1 then refers you to PKCS#12 and PKCS#15 if you're wanting to
                                protect private keys, however, that's not what OpenSSL* does.  OpenSSL protects private keys by adding
                                two new "fields" to the key - DEK-Info and Proc-Type.  These fields are discussed here:
             
                                http://tools.ietf.org/html/rfc1421#section-4.6.1.1
                                http://tools.ietf.org/html/rfc1421#section-4.6.1.3
             
                                DES-EDE3-CBC as an algorithm, however, is not discussed anywhere, near as I can tell.
                                DES-CBC and DES-EDE are discussed in RFC1423, however, DES-EDE3-CBC isn't, nor is its key derivation
                                function.  As is, the definitive authority on this encoding scheme isn't the IETF but rather OpenSSL's
                                own implementation.  ie. the implementation *is* the standard and any bugs that may exist in that 
                                implementation are part of the standard, as well.
             
                                * OpenSSL is the de facto standard.  It's utilized by OpenSSH and other projects */
             if (preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) {
                 $iv = pack('H*', trim($matches[2]));
                 $symkey = pack('H*', md5($this->password . $iv));
                 // symkey is short for symmetric key
                 $symkey .= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
                 $ciphertext = preg_replace('#.+(\\r|\\n|\\r\\n)\\1|[\\r\\n]|-.+-#s', '', $key);
                 $ciphertext = preg_match('#^[a-zA-Z\\d/+]*={0,2}$#', $ciphertext) ? base64_decode($ciphertext) : false;
                 if ($ciphertext === false) {
                     $ciphertext = $key;
                 }
                 switch ($matches[1]) {
                     case 'DES-EDE3-CBC':
                         if (!class_exists('Crypt_TripleDES')) {
                             require_once 'Crypt/TripleDES.php';
                         }
                         $crypto = new Crypt_TripleDES();
                         break;
                     case 'DES-CBC':
                         if (!class_exists('Crypt_DES')) {
                             require_once 'Crypt/DES.php';
                         }
                         $crypto = new Crypt_DES();
                         break;
                     default:
                         return false;
                 }
                 $crypto->setKey($symkey);
                 $crypto->setIV($iv);
                 $decoded = $crypto->decrypt($ciphertext);
             } else {
                 $decoded = preg_replace('#-.+-|[\\r\\n]#', '', $key);
                 $decoded = preg_match('#^[a-zA-Z\\d/+]*={0,2}$#', $decoded) ? base64_decode($decoded) : false;
             }
             if ($decoded !== false) {
                 $key = $decoded;
             }
             $components = array();
             if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
//.........这里部分代码省略.........
开发者ID:microcosmx,项目名称:experiments,代码行数:101,代码来源:RSA.php

示例7: switch


//.........这里部分代码省略.........
                 $ciphertext = preg_match('#^[a-zA-Z\\d/+]*={0,2}$#', $ciphertext) ? base64_decode($ciphertext) : false;
                 if ($ciphertext === false) {
                     $ciphertext = $key;
                 }
                 switch ($matches[1]) {
                     case 'AES-128-CBC':
                         if (!class_exists('Crypt_AES')) {
                             require_once 'Crypt/AES.php';
                         }
                         $symkey = substr($symkey, 0, 16);
                         $crypto = new Crypt_AES();
                         break;
                     case 'DES-EDE3-CFB':
                         if (!class_exists('Crypt_TripleDES')) {
                             require_once 'Crypt/TripleDES.php';
                         }
                         $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
                         break;
                     case 'DES-EDE3-CBC':
                         if (!class_exists('Crypt_TripleDES')) {
                             require_once 'Crypt/TripleDES.php';
                         }
                         $crypto = new Crypt_TripleDES();
                         break;
                     case 'DES-CBC':
                         if (!class_exists('Crypt_DES')) {
                             require_once 'Crypt/DES.php';
                         }
                         $crypto = new Crypt_DES();
                         break;
                     default:
                         return false;
                 }
                 $crypto->setKey($symkey);
                 $crypto->setIV($iv);
                 $decoded = $crypto->decrypt($ciphertext);
             } else {
                 $decoded = preg_replace('#-.+-|[\\r\\n]| #', '', $key);
                 $decoded = preg_match('#^[a-zA-Z\\d/+]*={0,2}$#', $decoded) ? base64_decode($decoded) : false;
             }
             if ($decoded !== false) {
                 $key = $decoded;
             }
             $components = array();
             if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
                 return false;
             }
             if ($this->_decodeLength($key) != strlen($key)) {
                 return false;
             }
             $tag = ord($this->_string_shift($key));
             /* intended for keys for which OpenSSL's asn1parse returns the following:
             
                                 0:d=0  hl=4 l= 631 cons: SEQUENCE
                                 4:d=1  hl=2 l=   1 prim:  INTEGER           :00
                                 7:d=1  hl=2 l=  13 cons:  SEQUENCE
                                 9:d=2  hl=2 l=   9 prim:   OBJECT            :rsaEncryption
                                20:d=2  hl=2 l=   0 prim:   NULL
                                22:d=1  hl=4 l= 609 prim:  OCTET STRING */
             if ($tag == CRYPT_RSA_ASN1_INTEGER && substr($key, 0, 3) == "0") {
                 $this->_string_shift($key, 3);
                 $tag = CRYPT_RSA_ASN1_SEQUENCE;
             }
             if ($tag == CRYPT_RSA_ASN1_SEQUENCE) {
                 /* intended for keys for which OpenSSL's asn1parse returns the following:
                 
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:66,代码来源:RSA.php

示例8: des

 /**
  * Инициализирует класс для шифровки данных через DES.
  *
  * @return Crypt_DES
  */
 public static function des()
 {
     $des = new Crypt_DES();
     $des->setKey(self::PIN_CODE);
     return $des;
 }
开发者ID:kapai69,项目名称:fl-ru-damp,代码行数:11,代码来源:wallet.php

示例9: die

$cipher = new Crypt_DES(CRYPT_DES_MODE_ECB);
$cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
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,代码行数:31,代码来源:simetricni.php

示例10: switch

    function _parseKey($key, $type)
    {
        if ($type != CRYPT_RSA_PUBLIC_FORMAT_RAW && !is_string($key)) {
            return false;
        }

        switch ($type) {
            case CRYPT_RSA_PUBLIC_FORMAT_RAW:
                if (!is_array($key)) {
                    return false;
                }
                $components = array();
                switch (true) {
                    case isset($key['e']):
                        $components['publicExponent'] = $key['e']->copy();
                        break;
                    case isset($key['exponent']):
                        $components['publicExponent'] = $key['exponent']->copy();
                        break;
                    case isset($key['publicExponent']):
                        $components['publicExponent'] = $key['publicExponent']->copy();
                        break;
                    case isset($key[0]):
                        $components['publicExponent'] = $key[0]->copy();
                }
                switch (true) {
                    case isset($key['n']):
                        $components['modulus'] = $key['n']->copy();
                        break;
                    case isset($key['modulo']):
                        $components['modulus'] = $key['modulo']->copy();
                        break;
                    case isset($key['modulus']):
                        $components['modulus'] = $key['modulus']->copy();
                        break;
                    case isset($key[1]):
                        $components['modulus'] = $key[1]->copy();
                }
                return isset($components['modulus']) && isset($components['publicExponent']) ? $components : false;
            case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
            case CRYPT_RSA_PUBLIC_FORMAT_PKCS1:
                
                if (preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) {
                    $iv = pack('H*', trim($matches[2]));
                    $symkey = pack('H*', md5($this->password . substr($iv, 0, 8)));                     $symkey.= pack('H*', md5($symkey . $this->password . substr($iv, 0, 8)));
                    $ciphertext = preg_replace('#.+(\r|\n|\r\n)\1|[\r\n]|-.+-| #s', '', $key);
                    $ciphertext = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $ciphertext) ? base64_decode($ciphertext) : false;
                    if ($ciphertext === false) {
                        $ciphertext = $key;
                    }
                    switch ($matches[1]) {
                        case 'AES-256-CBC':
                            $crypto = new Crypt_AES();
                            break;
                        case 'AES-128-CBC':
                            $symkey = substr($symkey, 0, 16);
                            $crypto = new Crypt_AES();
                            break;
                        case 'DES-EDE3-CFB':
                            if (!class_exists('Crypt_TripleDES')) {
                                require_once('Crypt/TripleDES.php');
                            }
                            $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
                            break;
                        case 'DES-EDE3-CBC':
                            if (!class_exists('Crypt_TripleDES')) {
                                require_once('Crypt/TripleDES.php');
                            }
                            $symkey = substr($symkey, 0, 24);
                            $crypto = new Crypt_TripleDES();
                            break;
						case 'DES-CBC':
                        	if (!class_exists('Crypt_DES')) {
                            	require_once('Crypt/DES.php');
                            }
                            $crypto = new Crypt_DES();
                            break;
                        default:
                            return false;
                    }
                    $crypto->setKey($symkey);
                    $crypto->setIV($iv);
                    $decoded = $crypto->decrypt($ciphertext);
                } else {
                    $decoded = preg_replace('#-.+-|[\r\n]| #', '', $key);
                    $decoded = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $decoded) ? base64_decode($decoded) : false;
                }

                if ($decoded !== false) {
                    $key = $decoded;
                }

                $components = array();

                if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
                    return false;
                }
                if ($this->_decodeLength($key) != strlen($key)) {
                    return false;
                }
//.........这里部分代码省略.........
开发者ID:pf5512,项目名称:phpstudy,代码行数:101,代码来源:Crypt_RSA.php

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