示例#1
0
    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testCrypt()
    {
        $rsa = new RSA();
        $rsa->loadKey('-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----');
        // public key
        $plaintext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed gravida felis sit amet nulla accumsan, sed mollis elit tristique. Vivamus fermentum mauris et tellus feugiat luctus. Suspendisse faucibus, orci sed feugiat lobortis, nulla nunc vestibulum nibh, sed vulputate ipsum felis ac nisl. Sed sit amet est a felis posuere mollis eu placerat risus. Mauris eget nisl condimentum, varius sapien vitae, mattis nisl. Nulla porta eu nulla at imperdiet. Integer sollicitudin, ipsum nec tempus rhoncus, ipsum massa elementum sapien, ac malesuada orci augue eu nibh. Quisque posuere porttitor magna id finibus. Nunc porttitor eros et erat semper sagittis. Pellentesque sed luctus sem. Sed vulputate massa mollis lacus tincidunt auctor. Praesent aliquet quis diam sit amet rutrum. Sed mauris sem, placerat sed ex ac, hendrerit lobortis enim. Etiam egestas ex orci. Integer in varius ex, nec scelerisque tortor.';
        //$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
        $ciphertext = $rsa->encrypt($plaintext);
        $rsa->loadKey('-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----');
        // private key
        $decryptedText = $rsa->decrypt($ciphertext);
        $this->assertEquals($decryptedText, $plaintext);
    }
示例#2
0
    public function testEncryptionModeNone()
    {
        $plaintext = 'a';
        $rsa = new RSA();
        $privatekey = '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
-----END RSA PRIVATE KEY-----';
        $rsa->loadKey($privatekey);
        $rsa->loadKey($rsa->getPublicKey());
        $rsa->setEncryptionMode(RSA::ENCRYPTION_NONE);
        $expected = '105b92f59a87a8ad4da52c128b8c99491790ef5a54770119e0819060032fb9e772ed6772828329567f3d7e9472154c1530f8156ba7fd732f52ca1c06' . '5a3f5ed8a96c442e4662e0464c97f133aed31262170201993085a589565d67cc9e727e0d087e3b225c8965203b271e38a499c92fc0d6502297eca712' . '4d04bd467f6f1e7c';
        $expected = pack('H*', $expected);
        $result = $rsa->encrypt($plaintext);
        $this->assertEquals($result, $expected);
        $rsa->loadKey($privatekey);
        $this->assertEquals(trim($rsa->decrypt($result), ""), $plaintext);
    }
 /**
  * Login with the set username and password.
  * @return LoginResult
  * @throws SteamException Thrown when Steam gives an unexpected response (e.g. Steam is down/having issues)
  * @throws \Exception Thrown when cookiefile is unable to be created.
  */
 public function doLogin()
 {
     if (!file_exists($this->_getCookiesFilePath())) {
         if (file_put_contents($this->_getCookiesFilePath(), '') === false) {
             throw new \Exception("Could not create cookiefile for {$this->username}.");
         }
     }
     if ($this->_isLoggedIn()) {
         $this->loggedIn = true;
         return LoginResult::LoginOkay;
     }
     $rsaResponse = $this->cURL('https://steamcommunity.com/login/getrsakey', null, ['username' => $this->username]);
     $rsaJson = json_decode($rsaResponse, true);
     if ($rsaJson == null) {
         return LoginResult::GeneralFailure;
     }
     if (!$rsaJson['success']) {
         return LoginResult::BadRSA;
     }
     $rsa = new RSA();
     $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     $key = ['modulus' => new BigInteger($rsaJson['publickey_mod'], 16), 'publicExponent' => new BigInteger($rsaJson['publickey_exp'], 16)];
     $rsa->loadKey($key, RSA::PUBLIC_FORMAT_RAW);
     $encryptedPassword = base64_encode($rsa->encrypt($this->password));
     $params = ['username' => $this->username, 'password' => urlencode($encryptedPassword), 'twofactorcode' => is_null($this->twoFactorCode) ? '' : $this->twoFactorCode, 'captchagid' => $this->requiresCaptcha ? $this->captchaGID : '-1', 'captcha_text' => $this->requiresCaptcha ? $this->captchaText : '', 'emailsteamid' => $this->requires2FA || $this->requiresEmail ? (string) $this->steamId : '', 'emailauth' => $this->requiresEmail ? $this->emailCode : '', 'rsatimestamp' => $rsaJson['timestamp'], 'remember_login' => 'false'];
     $loginResponse = $this->cURL('https://steamcommunity.com/login/dologin/', null, $params);
     $loginJson = json_decode($loginResponse, true);
     if ($loginJson == null) {
         return LoginResult::GeneralFailure;
     } else {
         if (isset($loginJson['captcha_needed']) && $loginJson['captcha_needed']) {
             $this->requiresCaptcha = true;
             $this->captchaGID = $loginJson['captcha_gid'];
             return LoginResult::NeedCaptcha;
         } else {
             if (isset($loginJson['emailauth_needed']) && $loginJson['emailauth_needed']) {
                 $this->requiresEmail = true;
                 $this->steamId = $loginJson['emailsteamid'];
                 return LoginResult::NeedEmail;
             } else {
                 if (isset($loginJson['requires_twofactor']) && $loginJson['requires_twofactor'] && !$loginJson['success']) {
                     $this->requires2FA = true;
                     return LoginResult::Need2FA;
                 } else {
                     if (isset($loginJson['login_complete']) && !$loginJson['login_complete']) {
                         return LoginResult::BadCredentials;
                     } else {
                         if ($loginJson['success']) {
                             $this->_setSession();
                             $this->loggedIn = true;
                             return LoginResult::LoginOkay;
                         }
                     }
                 }
             }
         }
     }
     return LoginResult::GeneralFailure;
 }
 public function encrypt($token)
 {
     defined('CRYPT_RSA_PKCS15_COMPAT') || define('CRYPT_RSA_PKCS15_COMPAT', true);
     $rsa = new Crypt_RSA();
     $rsa->loadKey($this->publicKey);
     $rsa->setEncryptionMode(Crypt_RSA::ENCRYPTION_PKCS1);
     return $rsa->encrypt($token);
 }
示例#5
0
 public function encrypt(DatabaseRow $row, User $receiver)
 {
     $rsa = new RSA();
     $rsa->loadKey($receiver->getPublicKey());
     $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
     $sharedRow = clone $row;
     $sharedRow->setAttributes(array());
     return $rsa->encrypt(json_encode($sharedRow));
 }
示例#6
0
 /**
  * @expectedException \LengthException
  */
 public function testSmallModulo()
 {
     $plaintext = 'x';
     $n = new BigInteger(base64_decode('272435F22706FA96DE26E980D22DFF67'), 256);
     $e = new BigInteger(base64_decode('158753FF2AF4D1E5BBAB574D5AE6B54D'), 256);
     $rsa = new RSA();
     $rsa->load(array('n' => $n, 'e' => $e));
     $rsa->encrypt($plaintext);
 }
示例#7
0
 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 );
     }
 }
示例#8
0
 protected function generateSecret($password)
 {
     $finder = new Finder();
     $root = $this->container->get('kernel')->getRootDir();
     $files = $finder->ignoreUnreadableDirs()->in($root . 'key/')->files()->name('uipubkey.pem');
     foreach ($files as $file) {
         $private_key_text = $file->getContent();
         break;
     }
     if (!$private_key_text) {
         throw new FileNotFoundException('Encryption key not found');
     }
     $rsa = new RSA();
     $rsa->loadKey($private_key_text);
     return base64_encode($rsa->encrypt($password));
 }
 /**
  * @Route("/asd", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $request = $this->get('request');
     $defaultData = array('name' => 'Type your file name here');
     $form = $this->createFormBuilder($defaultData)->add('name', 'text')->add('file', 'file', array('mapped' => false))->add('submit', 'submit')->getForm();
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             // perform some action, such as saving the task to the database
             $data = $form->getData();
             if ($form['file']->getData()) {
                 $filename = $form['file']->getData()->getClientOriginalName();
                 $uploadDir = dirname($this->container->getParameter('kernel.root_dir')) . '/web/bundles/framework/upload';
                 $form['file']->getData()->move($uploadDir, $filename);
                 $link = '/web/bundles/framework/upload' . '/' . $filename;
             }
         }
         $inputFile = $request->files->get('cache.xml');
         return $this->render('default/index.html.twig', array('cipher' => "", 'plain' => "", 'rsacipher' => "", 'rsaplain' => "", 'rsapk' => "", 'form' => $form->createView(), 'link' => $link));
     } else {
         $des = new DES();
         echo gettype($des);
         $des->setKey('This is my secret key');
         $plaintext = 'asda sda sdas dasd asdasdada sd';
         $cipher = $des->encrypt($plaintext);
         $plain = $des->decrypt($cipher);
         $rsa = new RSA();
         $rsa->createKey(1024);
         $rsaplain = "encrypt using RSA";
         $key = $rsa->createKey(1024);
         $rsa->loadKey($key['publickey']);
         $rsacipher = $rsa->encrypt($rsaplain);
         $rsa->loadKey($key['privatekey']);
         $rsadec = $rsa->decrypt($rsacipher);
         // replace this example code with whatever you need
         return $this->render('default/index.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'), 'cipher' => $cipher, 'plain' => $plain, 'rsacipher' => $key['publickey'], 'rsaplain' => $key['privatekey'], 'rsapk' => $rsa->getPublicKey(), 'form' => $form->createView()));
     }
 }
示例#10
0
 /**
  * Encrypt with the public key.
  *
  * @param $string
  *
  * @return string base64 encoded
  */
 public function encrypt($string)
 {
     return base64_encode($this->rsa_key->encrypt($string));
 }
示例#11
0
 public function lock()
 {
     $rsa = new RSA();
     $rsa->loadKey($this->publicKey);
     $this->password = $rsa->encrypt("valid:" . $this->decryptedPassword);
     $this->decryptedPassword = null;
 }
示例#12
0
文件: Utils.php 项目: Apretaste/Core
 /**
  * Encript a message using the user's public key.
  *
  * @author salvipascual
  * @param String $email
  * @param String $message
  * @return String64
  * */
 public function encript($email, $message)
 {
     // get the user's public key
     $connection = new Connection();
     $res = $connection->deepQuery("SELECT publickey FROM `keys` WHERE email='{$email}'");
     $publickey = $res[0]->publickey;
     // create the key if it does not exist
     if (empty($publickey)) {
         $keys = $this->recreateRSAKeys($email);
         $publickey = $keys["publickey"];
     }
     // encript and return
     $rsa = new RSA();
     $rsa->loadKey($publickey);
     $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
     return base64_encode($rsa->encrypt($message));
 }
示例#13
0
 public function testPrivateMSBlob()
 {
     $key = 'BwIAAACkAABSU0EyAAQAAAEAAQAnh6FFs6kYe/gmb9dzqsQKmtjFE9mxNAe9mEU3OwOEEfyI' . 'wkAx0/8dwh12fuP4wzNbdZAq4mmqCE6Lo8wTNNIJVNYEhKq5chHg1+hPDgfETFgtEO54JZSg' . '3cBZWEV/Tq3LHEX8CaLvHZxMEfFXbTfliFYMLoJ+YK1mpg9GYcmbrVmMAKSoOgETkkiJJzYm' . 'XftO3KOveBtvkAzjHxxSS1yP/Ba10BzeIleH96SbTuQtQRLXwRykdX9uazK+YsiSud9/PyLb' . 'gy5TI+o28OHq5P+0y5+a9IaAQ/92UwlrkHUYfhN/xTVlUIxKlTEdUQTIf+iHif8d4ABb3OdY' . 'JXZOW6fGeUP10jMyvbnrEoPDsYy9qfNk++0/8UP2NeO1IATszuZYg1nEXOW/5jmUxMCdiFyd' . 'p9ES211kpEZ4XcvjGaDlaQ+bLWj05i2m/9aHYcBrfcxxvlMa/9ZvrX4DfPWeydUDDDQ4+ntp' . 'T50BunSvmyf7cUk76Bf2sPgLXUQFoufEQ5g1Qo/v1uyhWBJzh6OSUO/DDXN/s8ec/tN05RQQ' . 'FZQ0na+v0hOCrV9IuRqtBuj4WAj1I/A1JjwyyP9Y/6yWFPM6EcS/6lyPy30lJPoULh7G29zk' . 'n7NVdTEkDtthdDjtX7Qhgd9qWvm5ADlmnvsS9A5m7ToOgQyOxtJoSlLitLbf/09LRycl/cdI' . 'zoMOCEdPe3DQcyEKqUPsghAq+DKw3uZpXwHzwTdfqlHSWAnHDggFKV1HZuWc1c4rV4k4b513TqE=';
     $plaintext = 'zzz';
     $privKey = new RSA();
     $privKey->load($key);
     $this->assertSame($privKey->getLoadedFormat(), 'MSBLOB');
     $this->assertGreaterThanOrEqual(1, strlen("{$privKey}"));
     $pubKey = new RSA();
     $pubKey->load($privKey->getPublicKey('msblob'));
     $this->assertGreaterThanOrEqual(1, strlen("{$pubKey}"));
     $ciphertext = $pubKey->encrypt($plaintext);
     $this->assertSame($privKey->decrypt($ciphertext), $plaintext);
 }
示例#14
0
文件: Openpgp.php 项目: horde/horde
 /**
  * Encrypt a secret key packet.
  *
  * @param OpenPGP_SecretKeyPacket $p    Secret key packet.
  * @param \phpseclib\Crypt\RSA $cipher  RSA cipher object.
  * @param OpenPGP_S2K $s2k              OpenPGP String-to-key object.
  * @param string $iv                    Initial vector.
  */
 protected function _encryptPrivateKey($p, $cipher, $s2k, $iv)
 {
     $cipher->setIV($iv);
     $secret = '';
     foreach ($p::$secret_key_fields[$p->algorithm] as $f) {
         $f = $p->key[$f];
         $secret .= pack('n', OpenPGP::bitlength($f)) . $f;
     }
     $secret .= hash('sha1', $secret, true);
     $p->encrypted_data = $iv . $cipher->encrypt($secret);
     $p->s2k = $s2k;
     $p->s2k_useage = 254;
     $p->symmetric_algorithm = 7;
 }
示例#15
0
 /**
  * Decrypt with RSAES-OAEP + MGF1+SHA256
  * 
  * @param string $plaintext
  * @param PublicKey $rsaPublicKey
  * @return string
  * @throws InvalidCiphertextException
  */
 protected static function rsaEncrypt($plaintext, PublicKey $rsaPublicKey)
 {
     static $rsa = null;
     if (!$rsa) {
         $rsa = new RSA();
         $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
         $rsa->setMGFHash('sha256');
     }
     $rsa->loadKey($rsaPublicKey->getKey());
     return $rsa->encrypt($plaintext);
 }
 /**
  * Login with the set username and password.
  * @param bool $mobile Set to true to login as a mobile user.
  * @param bool $relogin Set to true to force a fresh login session.
  * @return LoginResult
  * @throws SteamException Thrown when Steam gives an unexpected response (e.g. Steam is down/having issues)
  */
 public function doLogin($mobile = false, $relogin = false)
 {
     $this->mobile = $mobile;
     $this->_createAuthFile();
     $this->_createCookieFile();
     if ($this->_isLoggedIn() && !$relogin) {
         if ($this->mobileAuth != null) {
             $this->mobileAuth->setOauth(file_get_contents($this->getAuthFilePath()));
         }
         $this->loggedIn = true;
         return LoginResult::LoginOkay;
     }
     $rsaResponse = $this->cURL('https://steamcommunity.com/login/getrsakey', null, ['username' => $this->username]);
     $rsaJson = json_decode($rsaResponse, true);
     if ($rsaJson == null) {
         return LoginResult::GeneralFailure;
     }
     if (!$rsaJson['success']) {
         return LoginResult::BadRSA;
     }
     $rsa = new RSA();
     $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     $key = ['modulus' => new BigInteger($rsaJson['publickey_mod'], 16), 'publicExponent' => new BigInteger($rsaJson['publickey_exp'], 16)];
     $rsa->loadKey($key, RSA::PUBLIC_FORMAT_RAW);
     $encryptedPassword = base64_encode($rsa->encrypt($this->password));
     $params = ['username' => $this->username, 'password' => urlencode($encryptedPassword), 'twofactorcode' => is_null($this->twoFactorCode) ? '' : $this->twoFactorCode, 'captchagid' => $this->requiresCaptcha ? $this->captchaGID : '-1', 'captcha_text' => $this->requiresCaptcha ? $this->captchaText : '', 'emailsteamid' => $this->requires2FA || $this->requiresEmail ? (string) $this->steamId : '', 'emailauth' => $this->requiresEmail ? $this->emailCode : '', 'rsatimestamp' => $rsaJson['timestamp'], 'remember_login' => 'false'];
     if ($mobile) {
         $params['oauth_client_id'] = 'DE45CD61';
         $params['oauth_scope'] = 'read_profile write_profile read_client write_client';
         $params['loginfriendlyname'] = '#login_emailauth_friendlyname_mobile';
     }
     $loginResponse = $this->cURL('https://steamcommunity.com/login/dologin/', null, $params);
     $loginJson = json_decode($loginResponse, true);
     if ($loginJson == null) {
         return LoginResult::GeneralFailure;
     } else {
         if (isset($loginJson['captcha_needed']) && $loginJson['captcha_needed']) {
             $this->requiresCaptcha = true;
             $this->captchaGID = $loginJson['captcha_gid'];
             return LoginResult::NeedCaptcha;
         } else {
             if (isset($loginJson['emailauth_needed']) && $loginJson['emailauth_needed']) {
                 $this->requiresEmail = true;
                 $this->steamId = $loginJson['emailsteamid'];
                 return LoginResult::NeedEmail;
             } else {
                 if (isset($loginJson['requires_twofactor']) && $loginJson['requires_twofactor'] && !$loginJson['success']) {
                     $this->requires2FA = true;
                     return LoginResult::Need2FA;
                 } else {
                     if (isset($loginJson['login_complete']) && !$loginJson['login_complete']) {
                         return LoginResult::BadCredentials;
                     } else {
                         if ($loginJson['success']) {
                             if (isset($loginJson['oauth'])) {
                                 file_put_contents($this->getAuthFilePath(), $loginJson['oauth']);
                             }
                             $this->_setSession();
                             $this->loggedIn = true;
                             return LoginResult::LoginOkay;
                         }
                     }
                 }
             }
         }
     }
     return LoginResult::GeneralFailure;
 }
示例#17
0
文件: TAKOYAKI.php 项目: EmreTr1/rtr
 function createRsaKey($id, $pw, $sessionKey, $keyName, $eValue, $nValue)
 {
     $rsa = new RSA();
     $n = $eValue;
     // naver~trick
     $e = $nValue;
     // switch~them
     $rsa->modulus = new BigInteger($n, 16);
     $rsa->publicExponent = new BigInteger($e, 16);
     $key = $rsa->getPublicKey();
     $rsa->loadKey($key);
     $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $comVal = $this->getLenChar($sessionKey) + $sessionKey + $this->getLenChar($id) + $id;
     return bin2hex($rsa->encrypt($comVal + $this->getLenChar($pw) + $pw));
 }