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


PHP pkcs5_pad函数代码示例

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


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

示例1: getflashHtml

    /**
     * 输出新头像
     */
    public function getflashHtml()
    {
        $password = pkcs5_pad(time());
        $userinfo = model('User')->getUserInfo($GLOBALS['ts']['mid']);
        $defaultImg = $userinfo['avatar_big'];
        $uploadUrl = urlencode(U('public/Account/doSaveUploadAvatar'));
        echo ' <embed src="' . THEME_PUBLIC_URL . '/image/face.swf" quality="high" wmode="opaque" 
			FlashVars="uploadServerUrl=' . $uploadUrl . '&defaultImg=' . $defaultImg . '" 
			pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" 
			type="application/x-shockwave-flash" width="610" height="560"></embed>';
        exit;
    }
开发者ID:naliduo,项目名称:ThinkSNS,代码行数:15,代码来源:AvatarWidget.class.php

示例2: myCrypt

function myCrypt($input, $key)
{
    $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
    $input = pkcs5_pad($input, $size);
    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $key, $iv);
    $data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    $data = base64_encode($data);
    return $data;
}
开发者ID:qujsh,项目名称:myshop,代码行数:13,代码来源:crypt.php

示例3: encrypt

function encrypt($plainText, $key)
{
    $secretKey = hextobin(md5($key));
    $initVector = pack("C*", 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf);
    $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', '');
    $blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc');
    $plainPad = pkcs5_pad($plainText, $blockSize);
    if (mcrypt_generic_init($openMode, $secretKey, $initVector) != -1) {
        $encryptedText = mcrypt_generic($openMode, $plainPad);
        mcrypt_generic_deinit($openMode);
    }
    return bin2hex($encryptedText);
}
开发者ID:EasysoftTechnologies,项目名称:OliveHotels,代码行数:13,代码来源:Crypto.php

示例4: encrypt

function encrypt($input)
{
    $sKey = 'youkang12android';
    $iv = '1233211234567741';
    $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
    $input = pkcs5_pad($input, $size);
    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    //$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $sKey, $iv);
    $data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    return $data;
}
开发者ID:kevinstudio,项目名称:zaodianla,代码行数:14,代码来源:wx_sample.php

示例5: idtag_des_encode2

function idtag_des_encode2($key, $text)
{
    $y = pkcs5_pad($text);
    $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_CBC, '');
    //使用MCRYPT_DES算法,cbc模式
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    $ks = mcrypt_enc_get_key_size($td);
    mcrypt_generic_init($td, $key, $key);
    //初始处理
    $encrypted = mcrypt_generic($td, $y);
    //解密
    mcrypt_generic_deinit($td);
    //结束
    mcrypt_module_close($td);
    return base64_encode($encrypted);
}
开发者ID:noikiy,项目名称:zays,代码行数:16,代码来源:idtag_des2.php

示例6: encrypt

function encrypt($plain_text, $cipher_key)
{
    $iv = "0123456789012345";
    $sha_cipher_key = hash("sha256", $cipher_key);
    $padded_cipher_key = substr($sha_cipher_key, 0, 32);
    $padded_plain_text = pkcs5_pad($plain_text, 16);
    //    printf("sha256 key is %s\n", $sha_cipher_key);
    //    printf("padded cipher key is %s\n\n", $padded_cipher_key);
    //    printf("padded plain_text is %s\n\n", $padded_plain_text);
    # This is the way to do AES-256 using mcrypt PHP - its not AES-128 or anything other than that!
    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    mcrypt_generic_init($td, $padded_cipher_key, $iv);
    $encrypted = mcrypt_generic($td, $padded_plain_text);
    $encode = base64_encode($encrypted);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    #printf("\nencoded: %s", $encode);
    return $encode;
}
开发者ID:camcima,项目名称:pubnub-php-api,代码行数:19,代码来源:PubnubAES.php

示例7: diaspora_msg_build

function diaspora_msg_build($msg, $user, $contact, $prvkey, $pubkey, $public = false)
{
    $a = get_app();
    if ($public) {
        return diaspora_pubmsg_build($msg, $user, $contact, $prvkey, $pubkey);
    }
    logger('diaspora_msg_build: ' . $msg, LOGGER_DATA);
    // without a public key nothing will work
    if (!$pubkey) {
        logger('diaspora_msg_build: pubkey missing: contact id: ' . $contact['id']);
        return '';
    }
    $inner_aes_key = random_string(32);
    $b_inner_aes_key = base64_encode($inner_aes_key);
    $inner_iv = random_string(16);
    $b_inner_iv = base64_encode($inner_iv);
    $outer_aes_key = random_string(32);
    $b_outer_aes_key = base64_encode($outer_aes_key);
    $outer_iv = random_string(16);
    $b_outer_iv = base64_encode($outer_iv);
    $handle = $user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3);
    $padded_data = pkcs5_pad($msg, 16);
    $inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv);
    $b64_data = base64_encode($inner_encrypted);
    $b64url_data = base64url_encode($b64_data);
    $data = str_replace(array("\n", "\r", " ", "\t"), array('', '', '', ''), $b64url_data);
    $type = 'application/xml';
    $encoding = 'base64url';
    $alg = 'RSA-SHA256';
    $signable_data = $data . '.' . base64url_encode($type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($alg);
    $signature = rsa_sign($signable_data, $prvkey);
    $sig = base64url_encode($signature);
    $decrypted_header = <<<EOT
<decrypted_header>
  <iv>{$b_inner_iv}</iv>
  <aes_key>{$b_inner_aes_key}</aes_key>
  <author_id>{$handle}</author_id>
</decrypted_header>
EOT;
    $decrypted_header = pkcs5_pad($decrypted_header, 16);
    $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $outer_aes_key, $decrypted_header, MCRYPT_MODE_CBC, $outer_iv);
    $outer_json = json_encode(array('iv' => $b_outer_iv, 'key' => $b_outer_aes_key));
    $encrypted_outer_key_bundle = '';
    openssl_public_encrypt($outer_json, $encrypted_outer_key_bundle, $pubkey);
    $b64_encrypted_outer_key_bundle = base64_encode($encrypted_outer_key_bundle);
    logger('outer_bundle: ' . $b64_encrypted_outer_key_bundle . ' key: ' . $pubkey, LOGGER_DATA);
    $encrypted_header_json_object = json_encode(array('aes_key' => base64_encode($encrypted_outer_key_bundle), 'ciphertext' => base64_encode($ciphertext)));
    $cipher_json = base64_encode($encrypted_header_json_object);
    $encrypted_header = '<encrypted_header>' . $cipher_json . '</encrypted_header>';
    $magic_env = <<<EOT
<?xml version='1.0' encoding='UTF-8'?>
<diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env" >
  {$encrypted_header}
  <me:env>
    <me:encoding>base64url</me:encoding>
    <me:alg>RSA-SHA256</me:alg>
    <me:data type="application/xml">{$data}</me:data>
    <me:sig>{$sig}</me:sig>
  </me:env>
</diaspora>
EOT;
    logger('diaspora_msg_build: magic_env: ' . $magic_env, LOGGER_DATA);
    return $magic_env;
}
开发者ID:ZerGabriel,项目名称:friendica,代码行数:64,代码来源:diaspora.php

示例8: AES256CBC_encrypt

function AES256CBC_encrypt($data, $key, $iv)
{
    return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, str_pad($key, 32, ""), pkcs5_pad($data, 16), MCRYPT_MODE_CBC, str_pad($iv, 16, ""));
}
开发者ID:nextgensh,项目名称:friendica,代码行数:4,代码来源:crypto.php

示例9: desencrypt

/**
 * DES加密函数
 *
 * @param string $input
 * @param string $key
 */
function desencrypt($input, $key)
{
    $size = mcrypt_get_block_size('des', 'ecb');
    $input = pkcs5_pad($input, $size);
    $td = mcrypt_module_open('des', '', 'ecb', '');
    $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    @mcrypt_generic_init($td, $key, $iv);
    $data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    $data = base64_encode($data);
    return $data;
}
开发者ID:armebayelm,项目名称:thinksns-vietnam,代码行数:19,代码来源:extend.php

示例10: glob

		<div id="nav">
			<ul>
			<?php 
$files = glob("./files/*");
foreach ($files as $file) {
    $time = time();
    $fileName = explode("/", $file);
    $filePlace = sizeof($fileName) - 1;
    $url = "";
    if (isset($_GET['cipher'])) {
        $url .= "cipher=" . $p_cipher;
    }
    if (isset($_GET['encoding'])) {
        $url .= "&encoding=" . $p_encoding;
    }
    print "<li><a href=\"?{$url}&c=" . encode(encrypt(pkcs5_pad(genNonce(16) . "|" . $directory . "/" . $fileName[$filePlace], $blocksize), $cipher, $mode, $key, $iv), $p_encoding) . "\">" . ucwords($fileName[$filePlace]) . "</a></li>";
}
?>
			</ul>
		</div>
		<div id="content">
			<h1><?php 
print $title;
?>
</h1>
	<?php 
print @$theData;
?>
		</div>
</body>
</html>
开发者ID:4v4t4r,项目名称:CryptOMG,代码行数:31,代码来源:index.php

示例11: des_encode

/**
* Php DES encryption function
 *
 * @param String $ key key
 * @param String $ text string
 * @return String
*/
function des_encode($key, $text)
{
    $y = pkcs5_pad($text);
    $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_CBC, '');
    //Use MCRYPT_DES algorithm, cbc mode
    $ks = mcrypt_enc_get_key_size($td);
    mcrypt_generic_init($td, $key, $key);
    //Initial treatment
    $encrypted = mcrypt_generic($td, $y);
    //Decryption
    mcrypt_generic_deinit($td);
    //End
    mcrypt_module_close($td);
    return base64_encode($encrypted);
}
开发者ID:ajhalls,项目名称:KODExplorer,代码行数:22,代码来源:common.function.php

示例12: chiffrement

function chiffrement($decryptedMdp, $IV)
{
    /* Charge un chiffrement */
    $td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
    $size = mcrypt_get_block_size('rijndael-128', 'cbc');
    /* Crée le VI et détermine la taille de la clé */
    $iv = imap_base64($IV);
    /* Crée la clé */
    $key = 'a7bc27daf59679de';
    $decryptedMdp = pkcs5_pad($decryptedMdp, $size);
    /* Initialise le module de chiffrement pour le déchiffrement */
    mcrypt_generic_init($td, $key, $iv);
    /* Chiffre les données */
    $mdpEncrypted = mcrypt_generic($td, $decryptedMdp);
    /* Libère le gestionnaire de chiffrement */
    mcrypt_generic_deinit($td);
    return $mdpEncrypted;
}
开发者ID:jeoff09,项目名称:Project-Optimisation,代码行数:18,代码来源:chiffrer.php

示例13: ord

    $pad = ord($text[strlen($text) - 1]);
    if ($pad > strlen($text)) {
        return false;
    }
    if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
        return false;
    }
    return substr($text, 0, -1 * $pad);
}
$input = 'abcdefghijklmnopqrstuwvxyz';
$iv = '00000000';
$key = '1234567890123456';
// $c = mcrypt_module_open('blowfish', '', 'cfb', '');
// mcrypt_generic_init($c, $key, $iv);
// $enc = mcrypt_generic($c, $input);
// echo (unpack('h*', $enc)[1]) . PHP_EOL;
echo ' PHP :: Actual' . PHP_EOL;
echo '      IN: ' . strlen($input) . ' :: ' . $input . PHP_EOL;
// $input = pkcs5_pad($input, mcrypt_module_get_algo_block_size('blowfish'));
$enc = mcrypt_encrypt('blowfish', $key, pkcs5_pad($input, 8), 'ecb', $iv);
echo ' ECB OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
$enc = mcrypt_encrypt('blowfish', $key, pkcs5_pad($input, 8), 'cbc', $iv);
echo ' CBC OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
$enc = mcrypt_encrypt('blowfish', $key, $input, 'cfb', $iv);
echo ' CFB OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
$enc = mcrypt_encrypt('blowfish', $key, $input, 'ncfb', $iv);
echo 'NCFB OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
$enc = mcrypt_encrypt('blowfish', $key, $input, 'ofb', $iv);
echo ' OFB OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
$enc = mcrypt_encrypt('blowfish', $key, $input, 'nofb', $iv);
echo 'NOFB OUT: ' . strlen($enc) . ' :: ' . unpack('h*', $enc)[1] . PHP_EOL;
开发者ID:nexces,项目名称:R2Fish,代码行数:31,代码来源:test.php

示例14: strlen

{
    $pad = $blocksize - strlen($text) % $blocksize;
    return $text . str_repeat(chr($pad), $pad);
}
function pkcs5_unpad($text)
{
    $pad = ord($text[strlen($text) - 1]);
    if ($pad > strlen($text)) {
        return false;
    }
    if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
        return false;
    }
    return substr($text, 0, -1 * $pad);
}
$key = "20C86125F86DB932D0139D32D9208CEF52BAEC98F1E9BA2A";
$key = pack("H48", $key);
$iv = "0102030405060708";
$iv = pack("H16", $iv);
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($td, $key, $iv);
$str = base64_encode(mcrypt_generic($td, pkcs5_pad("123456", 8)));
echo $str;
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($td, $key, $iv);
$ttt = pkcs5_unpad(mdecrypt_generic($td, base64_decode($str)));
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
#echo $ttt;
开发者ID:quchunguang,项目名称:test,代码行数:31,代码来源:crypt.php

示例15: mcrypt_module_open

$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv_size = mcrypt_enc_get_iv_size($cipher);
//      AES Key        : 'd2cb415e067c7b13'
//      AES IV         : 'e36dc751d0433f05'
//      HMAC KEY       : 'd6cfaad283353507'
//      Ciphertext(b64): 'Ru7RLA4o+iQZNJXBx0iXtgWSQuV8/uqj6R6M59egKfHhaBFuMTl9Mpsb4yx6\nkgokQAf1HUcLg32zGCPo8bH4Df5RUPXWSUfHNb3cR7Mf5I8=\n'
//      HMACb16        : '0f291f903f6abc951084bedb2210f48b30c4eb3e1bcce99b0967c5fda99d72a6'
// How do you do 256-bit AES encryption in PHP vs. 128-bit AES encryption???
// The answer is:  Give it a key that's 32 bytes long as opposed to 16 bytes long.
// We're using 16 bytes:
$key128 = "d2cb415e067c7b13";
$iv = "e36dc751d0433f05";
$hmac_key = "d6cfaad283353507";
// This is the plain-text to be encrypted:
$cleartext = "s_hostname:jonasnuts.blogs.sapo.pt OR s_hostname:jonasnuts.com;1350305502";
$cleartext = pkcs5_pad($cleartext, mcrypt_get_block_size('des', 'cbc'));
printf("plainText: %s\n\n", $cleartext);
// The mcrypt_generic_init function initializes the cipher by specifying both
// the key and the IV.  The length of the key determines whether we're doing
// 128-bit, 192-bit, or 256-bit encryption.
// Let's do 256-bit encryption here:
// Now let's do 128-bit encryption:
if (mcrypt_generic_init($cipher, $key128, $iv) != -1) {
    // PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
    printf("len: %d", strlen($cleartext));
    $cipherText = mcrypt_generic($cipher, $cleartext);
    mcrypt_generic_deinit($cipher);
    // Display the result in hex.
    $b64ciphertext = base64_encode($cipherText);
    printf("Ciphertext(b64): %s (%d chars)\n", $b64ciphertext, strlen($b64ciphertext));
    printf("hmac (hex)     : %s\n\n", hash_hmac('sha256', $cipherText, $hmac_key));
开发者ID:xiaozhang535,项目名称:sola,代码行数:31,代码来源:encrypt.php


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