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


PHP mcrypt_module_get_algo_key_size函数代码示例

本文整理汇总了PHP中mcrypt_module_get_algo_key_size函数的典型用法代码示例。如果您正苦于以下问题:PHP mcrypt_module_get_algo_key_size函数的具体用法?PHP mcrypt_module_get_algo_key_size怎么用?PHP mcrypt_module_get_algo_key_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 function __construct($cipher)
 {
     $this->cipher = $cipher;
     $this->key_size = mcrypt_module_get_algo_key_size($cipher);
     $this->block_size = mcrypt_module_get_algo_block_size($cipher);
     $this->iv = str_repeat("", mcrypt_get_iv_size($cipher, 'ncfb'));
 }
开发者ID:CoR--,项目名称:LRphpLib,代码行数:7,代码来源:openpgp_mcrypt_wrapper.php

示例2: decrypt

    /**
     * Decrypt a text using Mcrypt
     *
     * @see http://maxime-ohayon.developpez.com/tutoriels/mcrypt
     * @param string $algorithm, ex : MCRYPT_3DES, MCRYPT_BLOWFISH, etc. see Mcrpyt doc
     * @param string $mode,      ex : MCRYPT_MODE_ECB, MCRYPT_MODE_NOFB, etc. see Mcrpyt doc
     * @param string $key        = your secret key or passphrase
     * @param string $encrypted  : your value to be decrypted
     */
    public static function decrypt($algorithm = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE_NOFB, $key = "mySecretKey", $encrypted = "encryptedText")
    {
        $key_size = mcrypt_module_get_algo_key_size($algorithm);
        $iv_size = mcrypt_get_iv_size($algorithm, $mode);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $key = substr($key, 0, $key_size);

        return mcrypt_decrypt($algorithm, $key, $cyphered, $mode, $iv);
    }
开发者ID:ronanguilloux,项目名称:PhpLib,代码行数:18,代码来源:Encryption.php

示例3: testBase64Mode

 public function testBase64Mode()
 {
     $algo = Mcrypt::ALGO_DES;
     $mode = Mcrypt::MODE_ECB;
     $key = Mcrypt::createRandomKey(mcrypt_module_get_algo_key_size($algo));
     $iv = Mcrypt::createRandomIv(mcrypt_get_iv_size($algo, $mode));
     $mcrypt = new Mcrypt($key, $iv, $algo, $mode);
     $mcrypt->setBase64Mode(false);
     $encrypted = $mcrypt->encrypt('foo');
     $this->assertSame(base64_encode($encrypted), $mcrypt->setBase64Mode(true)->encrypt('foo'));
 }
开发者ID:lytc,项目名称:sloths,代码行数:11,代码来源:McryptTest.php

示例4: validateEncryptionKey

 /**
  * Checks if a key is valid for {@link cryptAlgorithm}.
  * @param string $key the key to check
  * @return boolean the validation result
  * @throws CException if the supported key lengths of the cipher are unknown
  */
 protected function validateEncryptionKey($key)
 {
     if (is_string($key)) {
         $supportedKeyLengths = mcrypt_module_get_supported_key_sizes($this->cryptAlgorithm);
         if ($supportedKeyLengths) {
             if (!in_array($this->strlen($key), $supportedKeyLengths)) {
                 throw new CException(Yii::t('yii', 'Encryption key length can be {keyLengths}.', array('{keyLengths}' => implode(',', $supportedKeyLengths))));
             }
         } elseif (isset(self::$encryptionKeyMinimumLengths[$this->cryptAlgorithm])) {
             $minLength = self::$encryptionKeyMinimumLengths[$this->cryptAlgorithm];
             $maxLength = mcrypt_module_get_algo_key_size($this->cryptAlgorithm);
             if ($this->strlen($key) < $minLength || $this->strlen($key) > $maxLength) {
                 throw new CException(Yii::t('yii', 'Encryption key length must be between {minLength} and {maxLength}.', array('{minLength}' => $minLength, '{maxLength}' => $maxLength)));
             }
         } else {
             throw new CException(Yii::t('yii', 'Failed to validate key. Supported key lengths of cipher not known.'));
         }
     } else {
         throw new CException(Yii::t('yii', 'Encryption key should be a string.'));
     }
 }
开发者ID:reggi49,项目名称:plansys,代码行数:27,代码来源:CSecurityManager.php

示例5: getMaxKeySize

 /**
  * @return int
  */
 public function getMaxKeySize()
 {
     return mcrypt_module_get_algo_key_size($this->getAlgorithm());
 }
开发者ID:lytc,项目名称:sloths,代码行数:7,代码来源:Mcrypt.php

示例6: generateSessionKey

 public function generateSessionKey()
 {
     $key = '';
     if (!empty($this->cryptParams['cipher']) && !empty($this->cryptParams['mode'])) {
         $keysize = mcrypt_module_get_algo_key_size($this->cryptParams['cipher']);
         /* Generating random key using iv generation routines */
         if ($keysize > 0 && ($td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', $this->cryptParams['mode'], ''))) {
             if ($this->cryptParams['cipher'] == MCRYPT_RIJNDAEL_128) {
                 $keysize = 16;
                 if ($this->type == XMLSecurityKey::AES256_CBC) {
                     $keysize = 32;
                 } elseif ($this->type == XMLSecurityKey::AES192_CBC) {
                     $keysize = 24;
                 }
             }
             while (strlen($key) < $keysize) {
                 $key .= mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
             }
             mcrypt_module_close($td);
             $key = substr($key, 0, $keysize);
             $this->key = $key;
         }
     }
     return $key;
 }
开发者ID:MexinaD,项目名称:SuiteCRM,代码行数:25,代码来源:xmlseclibs.php

示例7: GeneratePrivateKey

 /**
  * Generate the private key to use for encryption/decryption
  * 
  * @param array $params
  * @return array $params
  */
 private function GeneratePrivateKey($params)
 {
     // Max size for the key by chosen algorhythm
     $size = mcrypt_module_get_algo_key_size($params["cipher"]);
     // reduce key to max. size supported
     $params["private_key"] = substr($params["public_key"], 0, $size);
     return $params;
 }
开发者ID:tymiles003,项目名称:FieldWorkManager,代码行数:14,代码来源:Encryption.php

示例8: var_dump

<?php

var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_256));
var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_192));
var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RC2));
var_dump(mcrypt_module_get_algo_key_size(MCRYPT_XTEA));
var_dump(mcrypt_module_get_algo_key_size(MCRYPT_CAST_128));
var_dump(mcrypt_module_get_algo_key_size(MCRYPT_BLOWFISH));
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:mcrypt_module_get_algo_key_size.php

示例9: encrypt

 /**
  * This method encrypts data and returns a CipherText object. You need it to decrypt the data back.
  *
  * @param string $cipher The cipher algorithm to use.
  * @param mixed $plainText The plaintext to encrypt.
  * @param binary $key An optional key. If not specified, PSL will generate it and return it within CipherText.
  * @param string $operationMode The cipher mode of operation to use. Defaults to CBC.
  * @param binary $iv An optional parameter. PSL will generate it if not given and return it within CipherText.
  * @throws Exception
  * @return \PSL\CipherText
  */
 public static function encrypt($cipher, $plainText, $key = null, $operationMode = 'cbc', $iv = null)
 {
     $operationMode = strtolower($operationMode);
     // If the key is null, we generate it on ourself.
     if ($key === null) {
         // Check whether the cipher is supported.
         $supportedCiphers = self::getSupportedCiphers();
         if (in_array($cipher, $supportedCiphers) === false) {
             throw new Exception("The cipher '{$cipher}' is not supported on this system. The following is a list of supported ciphers: " . implode(', ', $supportedCiphers));
         }
         // We will use the maximum strength.
         $length = mcrypt_module_get_algo_key_size($cipher);
         $key = Randomizer::getRandomBytes($length);
     }
     // Make sure we can actually encrypt with these details. Be strict.
     self::isCipherable($cipher, $key, $operationMode, true);
     // If the developer did not specify an IV, we generate a strong pseudo random one.
     if ($iv === null) {
         if (($ivSize = @mcrypt_get_iv_size($cipher, $operationMode)) === false) {
             throw new Exception("Could not retrieve an IV size for cipher '{$cipher}' using a operation mode '{$operationMode}'.");
         }
         $iv = Randomizer::getRandomBytes($ivSize);
     }
     // Padding for block cipher modes such as CBC and ECB.
     $padded = false;
     if (mcrypt_module_is_block_mode($operationMode) === true) {
         $padded = true;
         // Calculate how many bytes we need to add.
         $addBytes = $ivSize - strlen((string) $plainText) % $ivSize;
         if ($addBytes === 0) {
             // Important.
             $addBytes = $ivSize;
         }
         // Pad with chr($addBytes).
         $plainText .= str_repeat(chr($addBytes), $addBytes);
     }
     // The encryption.
     if (($cipherText = @mcrypt_encrypt($cipher, $key, $plainText, $operationMode, $iv)) === false) {
         throw new Exception("Could not encrypt with a cipher '{$cipher}' using a operation mode '{$operationMode}'.");
     }
     // Building the object with the right properties and returning it.
     $ct = new CipherText();
     $ct->cipherText = $cipherText;
     $ct->iv = $iv;
     $ct->operationMode = $operationMode;
     $ct->cipher = $cipher;
     $ct->key = $key;
     $ct->padded = $padded;
     // In case some one needs to know this.
     return $ct;
 }
开发者ID:phpsource,项目名称:PHP-Security-Library,代码行数:62,代码来源:Encrypter.php

示例10: decrypt

 public static function decrypt($val, $key = 'siteenligne', $iv = 'hmco3773')
 {
     $key_size = mcrypt_module_get_algo_key_size(MCRYPT_BLOWFISH);
     $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_NOFB);
     $key = substr($key, 0, $key_size);
     $crypte = urldecode($val);
     $crypte = base64_decode($crypte);
     $crypte = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $crypte, MCRYPT_MODE_NOFB, $iv);
     return $crypte;
 }
开发者ID:kingdom96,项目名称:Generateur-des-projets,代码行数:10,代码来源:Utils.php

示例11: mcrypt_module_get_algo_key_size

<?php

// normal usage of mcrypt
mcrypt_module_get_algo_key_size($c);
// no mcrypt usage
$mcrypt_create_iv = 2;
$x = 'mcrypt_enc_is_block_algorithm_mode';
开发者ID:exakat,项目名称:exakat,代码行数:7,代码来源:Extmcrypt.01.php

示例12: mcrypt_create_iv

$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
$key = substr(md5("very secret key"), 0, $ks);
mcrypt_generic_init($td, $key, $iv);
$encrypted = mcrypt_generic($td, "This is very important data");
VERIFY($encrypted !== "This is very important data");
mcrypt_generic_deinit($td);
mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encrypted);
mcrypt_generic_end($td);
mcrypt_module_close($td);
VS($decrypted, "This is very important data");
VERIFY(in_array("blowfish", mcrypt_list_algorithms()));
VERIFY(in_array("cbc", mcrypt_list_modes()));
VS(mcrypt_module_get_algo_block_size("blowfish"), 8);
VS(mcrypt_module_get_algo_key_size("blowfish"), 56);
VS(mcrypt_module_get_supported_key_sizes("blowfish"), array());
VS(mcrypt_module_get_supported_key_sizes("twofish"), array(16, 24, 32));
VS(mcrypt_module_is_block_algorithm_mode("cbc"), true);
VS(mcrypt_module_is_block_algorithm("blowfish"), true);
VS(mcrypt_module_is_block_mode("cbc"), true);
VS(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128), true);
VS(mcrypt_module_self_test("bogus"), false);
$text = "boggles the inivisble monkey will rule the world";
$key = "very secret key";
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$enc = mcrypt_encrypt(MCRYPT_XTEA, $key, $text, MCRYPT_MODE_ECB, $iv);
VS(bin2hex($enc), "f522c62002fa16129c8576bcddc6dd0f7ea81991103ba42962d94c8bfff3ee660d53b187d7e989540abf5a729c2f7baf");
$crypttext = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc, MCRYPT_MODE_ECB, $iv);
VS($crypttext, $text);
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:ext_mcrypt.php

示例13: plugin_accounts_crypte

function plugin_accounts_crypte($Texte, $action)
{
    //$algo = "blowfish"; // ou la constante php MCRYPT_BLOWFISH
    //$mode = "nofb"; // ou la constante php MCRYPT_MODE_NOFB
    $key_size = mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_256);
    //$iv_size = mcrypt_get_iv_size($algo, $mode);
    //$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $key = 'Ceci est une clé secrète';
    if ($action == 1) {
        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $Texte, MCRYPT_MODE_ECB, $iv);
        $crypttext = base64_encode($crypttext);
    } else {
        if ($action == 2) {
            $crypttext = "<script language='javascript'>document.write(AESEncryptCtr({$Texte},SHA256({$key}),256));</script>";
        } else {
            if ($action == 3) {
                $Texte = base64_decode($Texte);
                $crypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $Texte, MCRYPT_MODE_ECB, $iv);
            }
        }
    }
    return trim($crypttext);
}
开发者ID:geldarr,项目名称:hack-space,代码行数:24,代码来源:hook.php

示例14: mcrypt_list_algorithms

<?php

$algorithms = mcrypt_list_algorithms();
printf("%-18s %s %8s\n", "算法名", "最大支持密钥长度(字节)", "分组(block)/流式(stream)");
foreach ($algorithms as $cipher) {
    $max_key_size = mcrypt_module_get_algo_key_size($cipher);
    $stream_mode = mcrypt_module_is_block_algorithm($cipher) == TRUE ? "block" : "stream";
    printf("%-18s %3d %25s\n", $cipher, $max_key_size, $stream_mode);
}
开发者ID:xwhitesnow,项目名称:learngit,代码行数:9,代码来源:0_mcrypt_list_algorithms.php


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