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


PHP Crypto::createNewRandomKey方法代码示例

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


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

示例1: dfrn_deliver


//.........这里部分代码省略.........
    if (strpos($final_dfrn_id, ':') == 1) {
        $final_dfrn_id = substr($final_dfrn_id, 2);
    }
    if ($final_dfrn_id != $orig_id) {
        logger('dfrn_deliver: wrong dfrn_id.');
        // did not decode properly - cannot trust this site
        return 3;
    }
    $postvars['dfrn_id'] = $idtosend;
    $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
    if ($dissolve) {
        $postvars['dissolve'] = '1';
    }
    if ($contact['rel'] && $contact['rel'] != CONTACT_IS_SHARING && !$contact['blocked'] || $owner['page-flags'] == PAGE_COMMUNITY) {
        $postvars['data'] = $atom;
        $postvars['perm'] = 'rw';
    } else {
        $postvars['data'] = str_replace('<dfrn:comment-allow>1', '<dfrn:comment-allow>0', $atom);
        $postvars['perm'] = 'r';
    }
    $postvars['ssl_policy'] = $ssl_policy;
    if ($page) {
        $postvars['page'] = $page;
    }
    if ($rino > 0 && $rino_remote_version > 0 && !$dissolve) {
        logger('rino version: ' . $rino_remote_version);
        switch ($rino_remote_version) {
            case 1:
                // Deprecated rino version!
                $key = substr(random_string(), 0, 16);
                $data = aes_encrypt($postvars['data'], $key);
                break;
            case 2:
                // RINO 2 based on php-encryption
                try {
                    $key = Crypto::createNewRandomKey();
                } catch (CryptoTestFailed $ex) {
                    logger('Cannot safely create a key');
                    return -1;
                } catch (CannotPerformOperation $ex) {
                    logger('Cannot safely create a key');
                    return -1;
                }
                try {
                    $data = Crypto::encrypt($postvars['data'], $key);
                } catch (CryptoTestFailed $ex) {
                    logger('Cannot safely perform encryption');
                    return -1;
                } catch (CannotPerformOperation $ex) {
                    logger('Cannot safely perform encryption');
                    return -1;
                }
                break;
            default:
                logger("rino: invalid requested verision '{$rino_remote_version}'");
                return -1;
        }
        $postvars['rino'] = $rino_remote_version;
        $postvars['data'] = bin2hex($data);
        #logger('rino: sent key = ' . $key, LOGGER_DEBUG);
        if ($dfrn_version >= 2.1) {
            if ($contact['duplex'] && strlen($contact['pubkey']) || $owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']) || $contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey'])) {
                openssl_public_encrypt($key, $postvars['key'], $contact['pubkey']);
            } else {
                openssl_private_encrypt($key, $postvars['key'], $contact['prvkey']);
            }
        } else {
            if ($contact['duplex'] && strlen($contact['prvkey']) || $owner['page-flags'] == PAGE_COMMUNITY) {
                openssl_private_encrypt($key, $postvars['key'], $contact['prvkey']);
            } else {
                openssl_public_encrypt($key, $postvars['key'], $contact['pubkey']);
            }
        }
        logger('md5 rawkey ' . md5($postvars['key']));
        $postvars['key'] = bin2hex($postvars['key']);
    }
    logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA);
    $xml = post_url($contact['notify'], $postvars);
    logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
    $curl_stat = $a->get_curl_code();
    if (!$curl_stat || !strlen($xml)) {
        return -1;
    }
    // timed out
    if ($curl_stat == 503 && stristr($a->get_curl_headers(), 'retry-after')) {
        return -1;
    }
    if (strpos($xml, '<?xml') === false) {
        logger('dfrn_deliver: phase 2: no valid XML returned');
        logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
        return 3;
    }
    if ($contact['term-date'] != '0000-00-00 00:00:00') {
        logger("dfrn_deliver: {$url} back from the dead - removing mark for death");
        require_once 'include/Contact.php';
        unmark_for_death($contact);
    }
    $res = parse_xml_string($xml);
    return $res->status;
}
开发者ID:EmilienB,项目名称:friendica,代码行数:101,代码来源:items.php


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