本文整理汇总了PHP中phpseclib\Crypt\RSA::_convertPublicKey方法的典型用法代码示例。如果您正苦于以下问题:PHP RSA::_convertPublicKey方法的具体用法?PHP RSA::_convertPublicKey怎么用?PHP RSA::_convertPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpseclib\Crypt\RSA
的用法示例。
在下文中一共展示了RSA::_convertPublicKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
public function login($user_id, $user_pw, $do_finalize = true)
{
$keys = $this->getKeys();
$rsa = new RSA();
$rsa->modulus = new BigInteger($keys['nvalue'], 16);
$rsa->exponent = new BigInteger($keys['evalue'], 16);
$rsa->publicExponent = new BigInteger($keys['evalue'], 16);
$rsa->k = strlen($rsa->modulus->toBytes());
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->loadKey($rsa->_convertPublicKey($rsa->modulus, $rsa->exponent), CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$raw_data = $this->getLenChar($keys['sessionkey']) . $keys['sessionkey'] . $this->getLenChar($user_id) . $user_id . $this->getLenChar($user_pw) . $user_pw;
$enc_data = $rsa->encrypt($raw_data);
$login_url = 'https://nid.naver.com/nidlogin.login';
$headers = ['User-Agent' => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 TAKOYAKI", 'Accept' => 'text/html,application/xhtml+xml,' . 'application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' => 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding' => 'gzip, deflate', 'Referer' => 'http://www.naver.com/', 'Content-Type' => 'application/x-www-form-urlencoded'];
$params = "enctp" . "=" . "1";
$params .= "&encpw" . "=" . bin2hex($enc_data);
$params .= "&encnm" . "=" . $keys['keyname'];
$params .= "&svctype" . "=" . "0";
$params .= "&url=http://www.naver.com/&enc_url=http%3A%2F%2Fwww.naver.com%2F&postDataKey=&nvlong=&saveID=&smart_level=undefined";
$params .= "&id" . "=" . "";
$params .= "&pw" . "=" . "";
$resp = $this->postURL($login_url, $params, 10, $headers);
// echo "\n\nheader\n" . $resp ["header"] . "\n";
// echo "\n\nbody\n" . $resp ["body"] . "\n";
$this->logined = true;
echo "\n로그인에 성공했습니다\n";
if (strpos($resp["body"], "새로운")) {
// NEW DEVICE CHECK
$key = $this->getKey($resp["body"]);
$result = $this->Accept($key);
$exp = explode('Set-Cookie: ', $result);
$NID_SES3 = explode('Set-Cookie: NID_AUT=', $result);
$work = $NID_SES3[1];
$NID_SES2 = explode(';', $work);
$NID_SES = $NID_SES2[0];
$NID_AUT3 = explode('Set-Cookie: NID_AUT=', $result);
$work2 = $NID_AUT3[1];
$NID_AUT2 = explode(';', $work2);
$NID_AUT = $NID_AUT2[0];
$this->logined = true;
echo "\n새장치 등록에 성공했습니다\n";
} elseif (strpos($resp["body"], "않습니다")) {
$this->logined = false;
}
if ($do_finalize and strpos($resp["body"], "https://nid.naver.com/login/sso/finalize.nhn")) {
$finalize_url = explode("replace(\"", $resp["body"], 2)[1];
$finalize_url = explode("\")", $finalize_url, 2)[0];
// echo "finalize_url: " . $finalize_url . "\n";
$headers = ['User-Agent' => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 TAKOYAKI", 'Accept' => 'text/html,application/xhtml+xml,' . 'application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' => 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding' => 'gzip, deflate', 'Referer' => 'https://nid.naver.com/nidlogin.login'];
$resp = $this->postURL($finalize_url, $headers);
echo "파이널라이즈에 성공했습니다\n";
// var_dump ( $resp );
}
}
示例2: toKey
function toKey()
{
switch ($this->components['kty']) {
case 'RSA':
$rsa = new RSA();
$n = new BigInteger('0x' . bin2hex(JOSE_URLSafeBase64::decode($this->components['n'])), 16);
$e = new BigInteger('0x' . bin2hex(JOSE_URLSafeBase64::decode($this->components['e'])), 16);
if (array_key_exists('d', $this->components)) {
throw new JOSE_Exception_UnexpectedAlgorithm('RSA private key isn\'t supported');
} else {
$pem_string = $rsa->_convertPublicKey($n, $e);
}
$rsa->loadKey($pem_string);
return $rsa;
default:
throw new JOSE_Exception_UnexpectedAlgorithm('Unknown key type');
}
}
示例3: toKey
public function toKey()
{
switch ($this->components['kty']) {
case 'RSA':
$rsa = new phpseclib\Crypt\RSA();
$modulus = new phpseclib\Math\BigInteger('0x' . bin2hex(self::base64UrlDecode($this->components['n'])), 16);
$exponent = new phpseclib\Math\BigInteger('0x' . bin2hex(self::base64UrlDecode($this->components['e'])), 16);
if (array_key_exists('d', $this->components)) {
throw new \Exception('RSA private key isn\'t supported');
} else {
$pemStr = $rsa->_convertPublicKey($modulus, $exponent);
}
$rsa->loadKey($pemStr);
return $rsa;
case 'EC':
throw new \Exception('Elliptic Curve not supported');
default:
throw new \Exception('ffff');
}
}