本文整理汇总了PHP中Crypt_Hash类的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_Hash类的具体用法?PHP Crypt_Hash怎么用?PHP Crypt_Hash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Crypt_Hash类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getHMAC
function getHMAC($astrResponseData, $astrFileName, $astrMerchantID)
{
$strkey = $this->getKey($astrMerchantID, $astrFileName);
$strhexkey = $this->hexstr($strkey);
$hash = new Crypt_Hash('sha1');
$hash->setKey($strhexkey);
$digest = $hash->hash($astrResponseData);
$cleardigest = $this->strhex($digest);
return $cleardigest;
}
开发者ID:mydos,项目名称:JBIMS-Admission,代码行数:10,代码来源:EncryptionUtil.php
示例2: encrypt
protected function encrypt($plaintext)
{
if ($this->cipher == NULL) {
$hash = new Crypt_Hash('md5');
$hashed_key = bin2hex($hash->hash($this->application->encryption_key()));
$this->cipher = new Crypt_AES(CRYPT_AES_MODE_CBC);
$this->cipher->setKeyLength(256);
$this->cipher->setKey($hashed_key);
}
$iv = "";
for ($i = 0; $i < 8; $i++) {
$iv .= chr(mt_rand(0, 255));
}
$iv = bin2hex($iv);
$this->cipher->setIV($iv);
return $iv . bin2hex($this->cipher->encrypt($plaintext));
}
开发者ID:vaginessa,项目名称:WallOfVideos,代码行数:17,代码来源:ZiggeoAuth.php
示例3: verify
/**
* DSA verify.
*
* @param string $message Message.
* @param string $hash_alg Hash algorithm.
* @param Math_BigInteger $r r.
* @param Math_BigInteger $s s.
*
* @return bool True if verified.
*/
public function verify($message, $hash_alg, $r, $s)
{
$hash = new Crypt_Hash($hash_alg);
$hash_m = new Math_BigInteger($hash->hash($message), 256);
$g = new Math_BigInteger($this->_key->key['g'], 256);
$p = new Math_BigInteger($this->_key->key['p'], 256);
$q = new Math_BigInteger($this->_key->key['q'], 256);
$y = new Math_BigInteger($this->_key->key['y'], 256);
$w = $s->modInverse($q);
$hash_m_mul = $hash_m->multiply($w);
$u1_base = $hash_m_mul->divide($q);
$u1 = $u1_base[1];
$r_mul = $r->multiply($w);
$u2_base = $r_mul->divide($q);
$u2 = $u2_base[1];
$g_pow = $g->modPow($u1, $p);
$y_pow = $y->modPow($u2, $p);
$g_pow_mul = $g_pow->multiply($y_pow);
$g_pow_mul_mod_base = $g_pow_mul->divide($p);
$g_pow_mul_mod = $g_pow_mul_mod_base[1];
$v_base = $g_pow_mul_mod->divide($q);
$v = $v_base[1];
return $v->compare($r) == 0;
}
开发者ID:raz0rsdge,项目名称:horde,代码行数:34,代码来源:DSA.php
示例4: setPassword
/**
* Sets the password.
*
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
* $hash, $salt, $count, $dkLen
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
* Note: Could, but not must, extend by the child Crypt_* class
*
* @see Crypt/Hash.php
* @param String $password
* @param optional String $method
* @access public
*/
function setPassword($password, $method = 'pbkdf2')
{
$key = '';
switch ($method) {
default:
// 'pbkdf2'
$func_args = func_get_args();
// Hash function
$hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
// WPA and WPA2 use the SSID as the salt
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
$count = isset($func_args[4]) ? $func_args[4] : 1000;
// Keylength
$dkLen = isset($func_args[5]) ? $func_args[5] : $this->password_key_size;
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
switch (true) {
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
if (!class_exists('Crypt_Hash')) {
require_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $dkLen) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; ++$j) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$key = substr($key, 0, $dkLen);
break;
default:
$key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
}
}
$this->setKey($key);
}
开发者ID:santikrass,项目名称:apache,代码行数:60,代码来源:Base.php
示例5: setPassword
/**
* Sets the password.
*
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2} or pbkdf1:
* $hash, $salt, $count, $dkLen
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
* Note: Could, but not must, extend by the child Crypt_* class
*
* @see Crypt/Hash.php
* @param String $password
* @param optional String $method
* @return Boolean
* @access public
*/
function setPassword($password, $method = 'pbkdf2')
{
$key = '';
switch ($method) {
default:
// 'pbkdf2' or 'pbkdf1'
$func_args = func_get_args();
// Hash function
$hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
// WPA and WPA2 use the SSID as the salt
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
$count = isset($func_args[4]) ? $func_args[4] : 1000;
// Keylength
if (isset($func_args[5])) {
$dkLen = $func_args[5];
} else {
$dkLen = $method == 'pbkdf1' ? 2 * $this->password_key_size : $this->password_key_size;
}
switch (true) {
case $method == 'pbkdf1':
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hashObj = new Crypt_Hash();
$hashObj->setHash($hash);
if ($dkLen > $hashObj->getLength()) {
user_error('Derived key too long');
return false;
}
$t = $password . $salt;
for ($i = 0; $i < $count; ++$i) {
$t = $hashObj->hash($t);
}
$key = substr($t, 0, $dkLen);
$this->setKey(substr($key, 0, $dkLen >> 1));
$this->setIV(substr($key, $dkLen >> 1));
return true;
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $dkLen) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; ++$j) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$key = substr($key, 0, $dkLen);
break;
default:
$key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
}
}
$this->setKey($key);
return true;
}
开发者ID:ranamimran,项目名称:persivia,代码行数:85,代码来源:Base.php
示例6: setPassword
public function setPassword($password, $method = 'pbkdf2')
{
$key = '';
list(, , $hash, $salt, $count) = func_get_args();
if (!isset($hash)) {
$hash = 'sha1';
}
if (!isset($salt)) {
$salt = 'phpseclib';
}
if (!isset($count)) {
$count = 1000;
}
if (!class_exists('Crypt_Hash')) {
require_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $this->key_size) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; $j++) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$this->setKey(substr($key, 0, $this->key_size));
}
开发者ID:fkssei,项目名称:pigcms10,代码行数:30,代码来源:Crypt_Rijndael.php
示例7: getTokenTime
private static final function getTokenTime($username, $url)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha256');
$time = 0;
if ($token = Record::findOneFrom('SecureToken', "username = ? AND url = ?", array($username, bin2hex($hash->hash($url))))) {
$time = $token->time;
}
return $time;
}
开发者ID:julpi,项目名称:FreshCMS,代码行数:10,代码来源:SecureToken.php
示例8: _bakeCookie
private function _bakeCookie($time, $user)
{
if (!$this->_validateObject($user, true)) {
return false;
}
use_helper("Hash");
$hash = new Crypt_Hash("sha256");
$cookie = "exp=" . $time . "&id=" . $user->id . "&digest=" . bin2hex($hash->hash($user->username . $user->salt));
return $cookie;
}
开发者ID:pawedWolf,项目名称:wolfcms-pawusers,代码行数:10,代码来源:class.users.php
示例9: _hashBody
/**
*
*
*/
protected static function _hashBody($body, $method = 'sha1')
{
// prefer to use phpseclib
// http://phpseclib.sourceforge.net
if (class_exists('Crypt_Hash')) {
$hash = new Crypt_Hash($method);
return base64_encode($hash->hash($body));
} else {
// try standard PHP hash function
return base64_encode(hash($method, $body, true));
}
}
开发者ID:angrychimp,项目名称:php-dkim,代码行数:16,代码来源:DKIM.php
示例10: getTokenTime
private static final function getTokenTime($username, $url)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha256');
$time = 0;
$token = self::findOne(array('where' => 'username = :username AND url = :url', 'values' => array(':username' => $username, ':url' => bin2hex($hash->hash($url)))));
if ($token) {
$time = $token->time;
}
return $time;
}
开发者ID:ariksavage,项目名称:superior-optical-eyewear,代码行数:11,代码来源:SecureToken.php
示例11: setPassword
public function setPassword($password, $method)
{
$key = "";
switch (1) {
default:
list(, , $hash, $salt, $count) = func_get_args();
if (!$hash) {
$hash = "sha1";
}
if (!$salt) {
$salt = "phpseclib";
}
if (!$count) {
$count = 1000;
}
if (!class_exists("Crypt_Hash")) {
require_once "Crypt/Hash.php";
}
$i = 1;
while (strlen($key) < $this->key_size) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack("N", $i++));
for ($j = 2; $j <= $count; $j++) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
}
$this->setKey(substr($key, 0, $this->key_size));
}
开发者ID:belerweb,项目名称:pigcms,代码行数:33,代码来源:Crypt_Rijndael.php
示例12: generateHashedPassword
/**
* Generates a hashed version of a password.
*
* @see Hash Helper
*
* @param <type> $password
* @param <type> $salt
* @return <type>
*/
public static final function generateHashedPassword($password, $salt)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha512');
return bin2hex($hash->hash($password . $salt));
}
开发者ID:sindotnet,项目名称:cona,代码行数:15,代码来源:AuthUser.php
示例13: hash
/**
* Global hashing function
*
* @param int $algo Hash algorithm to use
* @param string $text Text to hash
* @param bool $binary Binary or hexa output
*
* @return bool|string
*/
static function hash($algo, $text, $binary = false)
{
$algos = array(self::MD2 => 'md2', self::MD5 => 'md5', self::MD5_96 => 'md5-96', self::SHA1 => 'sha1', self::SHA1_96 => 'sha1-96', self::SHA256 => 'sha256', self::SHA384 => 'sha384', self::SHA512 => 'sha512');
if (array_key_exists($algo, $algos)) {
$hash = new Crypt_Hash($algos[$algo]);
$fingerprint = $hash->hash($text);
if (!$binary) {
$fingerprint = bin2hex($fingerprint);
}
return $fingerprint;
}
return false;
}
开发者ID:OpenXtrem,项目名称:mediboard-test,代码行数:22,代码来源:CMbSecurity.class.php
示例14: hash
function hash($string, $key)
{
$hash = new Crypt_Hash('sha512');
$hash->setKey($key);
return $hash->hash($string);
}
开发者ID:KingsleyGU,项目名称:osticket,代码行数:6,代码来源:class.crypto.php
示例15: setPassword
/**
* Sets the password.
*
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
* $hash, $salt, $method
* Set $dkLen by calling setKeyLength()
*
* @param String $password
* @param optional String $method
* @access public
*/
function setPassword($password, $method = 'pbkdf2')
{
$key = '';
switch ($method) {
default:
// 'pbkdf2'
list(, , $hash, $salt, $count) = func_get_args();
if (!isset($hash)) {
$hash = 'sha1';
}
// WPA and WPA2 use the SSID as the salt
if (!isset($salt)) {
$salt = 'phpseclib';
}
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
if (!isset($count)) {
$count = 1000;
}
if (!class_exists('Crypt_Hash')) {
require_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $this->key_size) {
// $dkLen == $this->key_size
//$dk.= $this->_pbkdf($password, $salt, $count, $i++);
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; $j++) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
}
$this->setKey(substr($key, 0, $this->key_size));
}
开发者ID:Toxatoxa,项目名称:Sample-Code,代码行数:51,代码来源:rijndael.php
示例16: assertHMACsTo
protected function assertHMACsTo(Crypt_Hash $hash, $key, $message, $expected)
{
$hash->setKey($key);
$this->assertEquals(strtolower($expected), bin2hex($hash->hash($message)), sprintf("Failed asserting that '%s' HMACs to '%s' with key '%s'.", $message, $expected, $key));
}
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:5,代码来源:TestCase.php
示例17: _key_exchange
//.........这里部分代码省略.........
case 'arcfour128':
$encryptKeyLength = 16;
break;
case 'arcfour256':
$encryptKeyLength = 32;
break;
case 'none':
$encryptKeyLength = 0;
}
$keyLength = $decryptKeyLength > $encryptKeyLength ? $decryptKeyLength : $encryptKeyLength;
// through diffie-hellman key exchange a symmetric key is obtained
for ($i = 0; $i < count($kex_algorithms) && !in_array($kex_algorithms[$i], $this->kex_algorithms); $i++) {
}
if ($i == count($kex_algorithms)) {
user_error('No compatible key exchange algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
}
switch ($kex_algorithms[$i]) {
// see http://tools.ietf.org/html/rfc2409#section-6.2 and
// http://tools.ietf.org/html/rfc2412, appendex E
case 'diffie-hellman-group1-sha1':
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' . '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' . '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' . 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
break;
// see http://tools.ietf.org/html/rfc3526#section-3
// see http://tools.ietf.org/html/rfc3526#section-3
case 'diffie-hellman-group14-sha1':
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' . '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' . '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' . 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' . '98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' . '9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' . 'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' . '3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF';
break;
}
// For both diffie-hellman-group1-sha1 and diffie-hellman-group14-sha1
// the generator field element is 2 (decimal) and the hash function is sha1.
$g = new Math_BigInteger(2);
$prime = new Math_BigInteger($prime, 16);
$kexHash = new Crypt_Hash('sha1');
//$q = $p->bitwise_rightShift(1);
/* To increase the speed of the key exchange, both client and server may
reduce the size of their private exponents. It should be at least
twice as long as the key material that is generated from the shared
secret. For more details, see the paper by van Oorschot and Wiener
[VAN-OORSCHOT].
-- http://tools.ietf.org/html/rfc4419#section-6.2 */
$one = new Math_BigInteger(1);
$keyLength = min($keyLength, $kexHash->getLength());
$max = $one->bitwise_leftShift(16 * $keyLength);
// 2 * 8 * $keyLength
$max = $max->subtract($one);
$x = $one->random($one, $max);
$e = $g->modPow($x, $prime);
$eBytes = $e->toBytes(true);
$data = pack('CNa*', NET_SSH2_MSG_KEXDH_INIT, strlen($eBytes), $eBytes);
if (!$this->_send_binary_packet($data)) {
user_error('Connection closed by server');
return false;
}
$response = $this->_get_binary_packet();
if ($response === false) {
user_error('Connection closed by server');
return false;
}
extract(unpack('Ctype', $this->_string_shift($response, 1)));
if ($type != NET_SSH2_MSG_KEXDH_REPLY) {
user_error('Expected SSH_MSG_KEXDH_REPLY');
return false;
}
$temp = unpack('Nlength', $this->_string_shift($response, 4));
开发者ID:pacificcasinohotel,项目名称:pointsystem,代码行数:67,代码来源:SSH2.php
示例18: _convertPrivateKey
/**
* Convert a private key to the appropriate format.
*
* @see setPrivateKeyFormat()
*
* @param String $RSAPrivateKey
*
* @return String
*/
public function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
{
$num_primes = count($primes);
$raw = array('version' => $num_primes == 2 ? chr(0) : chr(1), 'modulus' => $n->toBytes(true), 'publicExponent' => $e->toBytes(true), 'privateExponent' => $d->toBytes(true), 'prime1' => $primes[1]->toBytes(true), 'prime2' => $primes[2]->toBytes(true), 'exponent1' => $exponents[1]->toBytes(true), 'exponent2' => $exponents[2]->toBytes(true), 'coefficient' => $coefficients[2]->toBytes(true));
// if the format in question does not support multi-prime rsa and multi-prime rsa was used,
// call _convertPublicKey() instead.
switch ($this->privateKeyFormat) {
case CRYPT_RSA_PRIVATE_FORMAT_XML:
if ($num_primes != 2) {
return false;
}
return "<RSAKeyValue>\r\n" . ' <Modulus>' . base64_encode($raw['modulus']) . "</Modulus>\r\n" . ' <Exponent>' . base64_encode($raw['publicExponent']) . "</Exponent>\r\n" . ' <P>' . base64_encode($raw['prime1']) . "</P>\r\n" . ' <Q>' . base64_encode($raw['prime2']) . "</Q>\r\n" . ' <DP>' . base64_encode($raw['exponent1']) . "</DP>\r\n" . ' <DQ>' . base64_encode($raw['exponent2']) . "</DQ>\r\n" . ' <InverseQ>' . base64_encode($raw['coefficient']) . "</InverseQ>\r\n" . ' <D>' . base64_encode($raw['privateExponent']) . "</D>\r\n" . '</RSAKeyValue>';
break;
case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
if ($num_primes != 2) {
return false;
}
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
$encryption = !empty($this->password) || is_string($this->password) ? 'aes256-cbc' : 'none';
$key .= $encryption;
$key .= "\r\nComment: " . $this->comment . "\r\n";
$public = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']);
$source = pack('Na*Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption, strlen($this->comment), $this->comment, strlen($public), $public);
$public = base64_encode($public);
$key .= 'Public-Lines: ' . (strlen($public) + 32 >> 6) . "\r\n";
$key .= chunk_split($public, 64);
$private = pack('Na*Na*Na*Na*', strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'], strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']);
if (empty($this->password) && !is_string($this->password)) {
$source .= pack('Na*', strlen($private), $private);
$hashkey = 'putty-private-key-file-mac-key';
} else {
$private .= crypt_random_string(16 - (strlen($private) & 15));
$source .= pack('Na*', strlen($private), $private);
if (!class_exists('Crypt_AES')) {
require_once 'AES.php';
}
$sequence = 0;
$symkey = '';
while (strlen($symkey) < 32) {
$temp = pack('Na*', $sequence++, $this->password);
$symkey .= pack('H*', sha1($temp));
}
$symkey = substr($symkey, 0, 32);
$crypto = new Crypt_AES();
$crypto->setKey($symkey);
$crypto->disablePadding();
$private = $crypto->encrypt($private);
$hashkey = 'putty-private-key-file-mac-key' . $this->password;
}
$private = base64_encode($private);
$key .= 'Private-Lines: ' . (strlen($private) + 32 >> 6) . "\r\n";
$key .= chunk_split($private, 64);
if (!class_exists('Crypt_Hash')) {
require_once 'Hash.php';
}
$hash = new Crypt_Hash('sha1');
$hash->setKey(pack('H*', sha1($hashkey)));
$key .= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";
return $key;
default:
// eg. CRYPT_RSA_PRIVATE_FORMAT_PKCS1
$components = array();
foreach ($raw as $name => $value) {
$components[$name] = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($value)), $value);
}
$RSAPrivateKey = implode('', $components);
if ($num_primes > 2) {
$OtherPrimeInfos = '';
for ($i = 3; $i <= $num_primes; ++$i) {
// OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo
//
// OtherPrimeInfo ::= SEQUENCE {
// prime INTEGER, -- ri
// exponent INTEGER, -- di
// coefficient INTEGER -- ti
// }
$OtherPrimeInfo = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true));
$OtherPrimeInfo .= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true));
$OtherPrimeInfo .= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true));
$OtherPrimeInfos .= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo);
}
$RSAPrivateKey .= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos);
}
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
if (!empty($this->password) || is_string($this->password)) {
$iv = crypt_random_string(8);
$symkey = pack('H*', md5($this->password . $iv));
// symkey is short for symmetric key
$symkey .= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
if (!class_exists('Crypt_TripleDES')) {
require_once 'TripleDES.php';
//.........这里部分代码省略.........
开发者ID:kapai69,项目名称:fl-ru-damp,代码行数:101,代码来源:RSA.php
示例19: _emsa_pkcs1_v1_5_encode
public function _emsa_pkcs1_v1_5_encode($m, $emLen)
{
$h = $this->hash->hash($m);
if ($h === false) {
return false;
}
switch ($this->hashName) {
case 'md2':
$t = pack('H*', '3020300c06082a864886f70d020205000410');
break;
case 'md5':
$t = pack('H*', '3020300c06082a864886f70d020505000410');
break;
case 'sha1':
$t = pack('H*', '3021300906052b0e03021a05000414');
break;
case 'sha256':
$t = pack('H*', '3031300d060960864801650304020105000420');
break;
case 'sha384':
$t = pack('H*', '3041300d060960864801650304020205000430');
break;
case 'sha512':
$t = pack('H*', '3051300d060960864801650304020305000440');
}
$t .= $h;
$tLen = strlen($t);
if ($emLen < $tLen + 11) {
user_error('Intended encoded message length too short');
return false;
}
$ps = str_repeat(chr(255), $emLen - $tLen - 3);
$em = '' . "" . '' . $ps . '' . "" . '' . $t;
return $em;
}
开发者ID:fkssei,项目名称:pigcms10,代码行数:35,代码来源:Crypt_RSA.php
示例20: switch
/**
* EMSA-PKCS1-V1_5-ENCODE
*
* See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.
*
* @access private
* @param String $m
* @param Integer $emLen
* @return String
*/
function _emsa_pkcs1_v1_5_encode($m, $emLen)
{
$h = $this->hash->hash($m);
if ($h === false) {
return false;
}
// see http://tools.ietf.org/html/rfc3447#page-43
switch ($this->hashName) {
case 'md2':
$t = pack('H*', '3020300c06082a864886f70d020205000410');
break;
case 'md5':
$t = pack('H*', '3020300c06082a864886f70d020505000410');
break;
case 'sha1':
$t = pack('H*', '3021300906052b0e03021a05000414');
break;
case 'sha256':
$t = pack('H*', '3031300d060960864801650304020105000420');
break;
case 'sha384':
$t = pack('H*', '3041300d060960864801650304020205000430');
break;
case 'sha512':
$t = pack('H*', '3051300d060960864801650304020305000440');
}
$t .= $h;
$tLen = strlen($t);
if ($emLen < $tLen + 11) {
user_error('Intended encoded message length too short', E_USER_NOTICE);
return false;
}
$ps = str_repeat(chr(0xff), $emLen - $tLen - 3);
$em = "{$ps}{$t}";
return $em;
}
开发者ID:microcosmx,项目名称:experiments,代码行数:46,代码来源:RSA.php
注:本文中的Crypt_Hash类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论