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


PHP Crypt_RSA::sign方法代码示例

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


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

示例1: signMessage

 public function signMessage($privatekey, $message)
 {
     /**
      * Test code:
      * 
      * $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
      * extract($rsa->createKey());
      * $spotSigning = new SpotSigning();
      * $x = $spotSigning->signMessage($privatekey, 'testmessage');
      * var_dump($x);
      * var_dump($spotSigning->checkRsaSignature('testmessage', $x['signature'], $x['publickey'], false));
      *
      */
     if (empty($privatekey)) {
         throw new InvalidPrivateKeyException();
     }
     # if
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->loadKey($privatekey);
     # extract de public key
     $signature = $rsa->sign($message);
     $publickey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     return array('signature' => base64_encode($signature), 'publickey' => array('modulo' => base64_encode($publickey['n']->toBytes()), 'exponent' => base64_encode($publickey['e']->toBytes())), 'message' => $message);
 }
开发者ID:Ernie69,项目名称:spotweb,代码行数:25,代码来源:Services_Signing_Base.php

示例2: sign

 /**
  * Generate base64-encoded signature for the given byte string
  * using our private key.
  *
  * @param string $bytes as raw byte string
  * @return string base64url-encoded signature
  */
 public function sign($bytes)
 {
     $sig = $this->privateKey->sign($bytes);
     if ($sig === false) {
         throw new ServerException('Could not sign data');
     }
     return Magicsig::base64_url_encode($sig);
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:15,代码来源:Magicsig.php

示例3: activateKeyGen

function activateKeyGen($key, $hwid, $privKey, $offline = false)
{
    $rsa = new Crypt_RSA();
    $rsa->loadKey($privKey);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $rsa->setHash('sha512');
    $activateKey = $rsa->sign(sha1(base64_decode($key) . hash('sha512', $hwid, true)));
    if ($offline) {
        $license = '------BEGIN ACTIVATION KEY------' . "\r\n";
        $license .= chunk_split(base64_encode($activateKey));
        $license .= '------END ACTIVATION KEY------';
    } else {
        $license = base64_encode($activateKey);
    }
    return $license;
}
开发者ID:hartmantam,项目名称:php-license-system,代码行数:16,代码来源:activateKeyGenerator.php

示例4: CreateLicense

 public static function CreateLicense($licensee, $type)
 {
     // Gleiche Generalisierung wie am Client:
     $licenseeGen = self::GeneralizeDataString($licensee);
     $dataStr = $licenseeGen . (int) $type;
     // "ERIKAMUSTERMANN2"
     $rsa = new Crypt_RSA();
     // Neue RSA-Klasse erstellen
     // Setzen der RSA-Optionen auf die, die auch am Client verwendet werden:
     $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_XML);
     $rsa->setHash('SHA1');
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     // privaten Schlüssel laden
     $rsa->loadKey(self::privateKey);
     // Erstellen der Signatur
     $signature = $rsa->sign($dataStr);
     // Formatierte Lizenzdaten zurückgeben
     return self::FormatLicense($licensee, $type, $signature);
 }
开发者ID:vainamov,项目名称:license-system,代码行数:19,代码来源:LicenseCreator.php

示例5: TYPE

 TYPE (0-блок, 1-тр-я)     FF (256)
 BLOCK_ID   				       FF FF FF FF (4 294 967 295)
 TIME       					       FF FF FF FF (4 294 967 295)
 USER_ID                         FF FF FF FF FF (1 099 511 627 775)
 LEVEL                              FF (256)
 SIGN                               от 128 байта до 512 байт. Подпись от TYPE, BLOCK_ID, PREV_BLOCK_HASH, TIME, USER_ID, LEVEL, MRKL_ROOT
 Далее - тело блока (Тр-ии)
 */
 // подписываем нашим нод-ключем заголовок блока
 $rsa = new Crypt_RSA();
 $rsa->loadKey($node_private_key);
 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
 //$rsa->setHash('sha256');
 $for_sign = "0,{$new_block_id},{$testBlock->prev_block['hash']},{$time},{$my_user_id},{$testBlock->level},{$mrkl_root}";
 debug_print('$for_sign=' . $for_sign, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 $signature = $rsa->sign($for_sign);
 unset($rsa);
 list(, $signature_hex) = unpack("H*", $signature);
 debug_print('$signature_hex = ' . $signature_hex, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 // хэш шапки блока. нужен для сравнивания с другими и у кого будет меньше - у того блок круче
 $header_hash = ParseData::dsha256("{$my_user_id},{$new_block_id},{$prev_head_hash}");
 debug_print("header_hash={$header_hash}", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 $data = "{$new_block_id}\t{$time}\t{$testBlock->level}\t{$my_user_id}\t{$header_hash}\t{$signature_hex}\t{$mrkl_root}";
 debug_print($data, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 $file = save_tmp_644('FTB', $data);
 // для тестов получим что там есть
 $tmp_testblock_data = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT *\n\t\t\tFROM `" . DB_PREFIX . "testblock`\n\t\t\t", 'fetch_array');
 debug_print($tmp_testblock_data, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 debug_print("LOAD DATA LOCAL INFILE  '{$file}' REPLACE INTO TABLE `" . DB_PREFIX . "testblock`", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 // т.к. эти данные создали мы сами, то пишем их сразу в таблицу проверенных данных, которые будут отправлены другим нодам
 $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tLOAD DATA LOCAL INFILE  '{$file}' REPLACE INTO TABLE `" . DB_PREFIX . "testblock`\n\t\t\tFIELDS TERMINATED BY '\t'\n\t\t\t(`block_id`,`time`,`level`,`user_id`, @header_hash, @signature, @mrkl_root)\n\t\t\tSET `header_hash` = UNHEX(@header_hash),\n\t\t\t\t   `signature` = UNHEX(@signature),\n\t\t\t\t   `mrkl_root` = UNHEX(@mrkl_root)\n\t\t\t");
开发者ID:scuba323,项目名称:dcoin,代码行数:31,代码来源:testblock_generator.php

示例6: sign

 /**
  * Generate base64-encoded signature for the given byte string
  * using our private key.
  *
  * @param string $bytes as raw byte string
  * @return string base64-encoded signature
  */
 public function sign($bytes)
 {
     $sig = $this->privateKey->sign($bytes);
     return Magicsig::base64_url_encode($sig);
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:12,代码来源:Magicsig.php

示例7: signature_for_message

 public function signature_for_message($message, $use_key = false)
 {
     $hash_algorithm = 'sha256';
     // Sign with the private (local) key
     if (!$use_key) {
         if (!$this->key_local) {
             throw new Exception('No signing key has been set');
         }
         $use_key = $this->key_local;
     }
     $this->ensure_crypto_loaded();
     $rsa = new Crypt_RSA();
     $rsa->loadKey($use_key);
     // This is the older signature mode; phpseclib's default is the preferred CRYPT_RSA_SIGNATURE_PSS; however, Forge JS doesn't yet support this. More info: https://en.wikipedia.org/wiki/PKCS_1
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     // Don't do this: Crypt_RSA::sign() already calculates the digest of the hash
     // 		$hash = new Crypt_Hash($hash_algorithm);
     // 		$hashed = $hash->hash($message);
     // 		if ($this->debug) $this->log("Message hash (hash=$hash_algorithm) (hex): ".bin2hex($hashed));
     // phpseclib defaults to SHA1
     $rsa->setHash($hash_algorithm);
     $encrypted = $rsa->sign($message);
     if ($this->debug) {
         $this->log('Signed hash (mode=' . CRYPT_RSA_SIGNATURE_PKCS1 . ') (hex): ' . bin2hex($encrypted));
     }
     $signature = base64_encode($encrypted);
     if ($this->debug) {
         $this->log("Message signature (base64): {$signature}");
     }
     return $signature;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-Cambridge,代码行数:31,代码来源:class-udrpc.php

示例8: count

        main_unlock();
        exit;
    }
    debug_print($max_other_currencies_votes, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    $total_count_currencies = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT count(`id`)\n\t\t\tFROM `" . DB_PREFIX . "currency`\n\t\t\t", 'fetch_one');
    foreach ($max_other_currencies_votes as $currency_id => $count_and_votes) {
        $new_max_other_currencies[$currency_id] = get_max_vote($count_and_votes, 0, $total_count_currencies, 10);
    }
    if (get_community_users($db)) {
        $my_prefix = $testBlock->user_id . '_';
    } else {
        $my_prefix = '';
    }
    $node_private_key = get_node_private_key($db, $my_prefix);
    $json_data = json_encode($new_max_other_currencies);
    // подписываем нашим нод-ключем данные транзакции
    $data_for_sign = ParseData::findType('new_max_other_currencies') . ",{$time},{$my_user_id},{$json_data}";
    $rsa = new Crypt_RSA();
    $rsa->loadKey($node_private_key);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $signature = $rsa->sign($data_for_sign);
    debug_print('$data_for_sign=' . $data_for_sign . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    // создаем тр-ию. пишем $block_id, на момент которого были актуальны голоса в табле 'pct'
    $data = dec_binary(ParseData::findType('new_max_other_currencies'), 1) . dec_binary($time, 4) . ParseData::encode_length_plus_data($my_user_id) . ParseData::encode_length_plus_data($json_data) . ParseData::encode_length_plus_data($signature);
    $hash = ParseData::dsha256($data);
    insert_tx($data, $db);
    $new_tx_data['data'] = $data;
    $new_tx_data['hash'] = hextobin(md5($data));
    tx_parser($new_tx_data, true);
}
main_unlock();
开发者ID:scuba323,项目名称:dcoin,代码行数:31,代码来源:max_other_currencies_generator.php

示例9: signMessage

 /**
  * Sign a message using a private RSA key
  *
  * @param string $payload The message to be signed
  * @param string $private_key An RSA private key
  * @return string A base64-encoded and url-encoded hash of the $payload_string
  */
 private function signMessage($payload, $private_key)
 {
     $signature_urlencoded = '';
     $rsa_signature = new \Crypt_RSA();
     $rsa_signature->loadKey($private_key);
     $rsa_signature->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa_signature->setHash('md5');
     $payload_base64 = urldecode(substr($payload, 0, -6));
     $signature_binary = $rsa_signature->sign($payload_base64);
     $signature_base64 = base64_encode($signature_binary);
     $signature_urlencoded = urlencode($signature_base64) . "decode";
     return $signature_urlencoded;
 }
开发者ID:abenity,项目名称:abenity-php,代码行数:20,代码来源:ApiClient.php

示例10: createSignature

 public function createSignature($text)
 {
     $rsa = new Crypt_RSA();
     $rsa->loadKey($this['private_key']);
     return $rsa->sign($text);
 }
开发者ID:Krassmus,项目名称:LehrMarktplatz,代码行数:6,代码来源:LernmarktplatzIdentity.php

示例11: encrypt_and_sign

function encrypt_and_sign($pass, $encrypt_private_key, $data_for_sign)
{
    debug_print("pass={$pass}", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print("encrypt_private_key={$encrypt_private_key}", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print("data_for_sign={$data_for_sign}", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    if ($pass !== '') {
        debug_print("pass exists", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
        $aes = new Crypt_AES(CRYPT_AES_MODE_ECB);
        $aes = new Crypt_AES(CRYPT_AES_MODE_ECB);
        $aes->setKey(md5($pass));
        $user_private_key = $aes->decrypt($encrypt_private_key);
        unset($aes);
    } else {
        $user_private_key = $encrypt_private_key;
    }
    debug_print("user_private_key=" . $user_private_key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    $rsa = new Crypt_RSA();
    $rsa->loadKey($user_private_key);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $signature = $rsa->sign($data_for_sign);
    unset($rsa);
    debug_print("signature=" . $signature, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    return $signature;
}
开发者ID:scuba323,项目名称:dcoin,代码行数:24,代码来源:fns-main.php

示例12: die

include 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
$msg = "";
$color = "";
$cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
if (isset($_POST['potpisi'])) {
    file_put_contents('potpis.txt', '');
    $cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $privatekey = file_get_contents('./privatni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $rsa->loadKey($privatekey);
    //$signature = base64_encode($rsa->sign(base64_decode($cisti_tekst)));
    //$signature = base64_encode($rsa->sign(base64_decode($cisti_tekst)));
    $signature = $rsa->sign($cisti_tekst);
    $signature = base64_encode($signature);
    $ret = file_put_contents('potpis.txt', $signature, FILE_APPEND | LOCK_EX);
    if ($ret === false) {
        die('Neuspješna pohrana u datoteku');
    } else {
        echo "U datoteku je pohranjeno: " . $ret . " bajtova";
    }
}
if (isset($_POST['provjeri'])) {
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $publickey = file_get_contents('./javni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $rsa->loadKey($publickey);
    $signature = file_get_contents('./potpis.txt', FILE_USE_INCLUDE_PATH);
    $signature = base64_decode($signature);
开发者ID:jtrupina,项目名称:os2-project,代码行数:30,代码来源:digitalnipotpis.php


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