{"id":28359926,"url":"https://github.com/phpseclib/phpseclib3_rector","last_synced_at":"2026-03-02T10:02:31.889Z","repository":{"id":291484842,"uuid":"977705651","full_name":"phpseclib/phpseclib3_rector","owner":"phpseclib","description":"Rector rules to upgrade a phpseclib v2.0 install to phpseclib v3.0","archived":false,"fork":false,"pushed_at":"2026-01-23T18:11:26.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-15T22:28:40.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpseclib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-04T19:45:52.000Z","updated_at":"2026-01-23T18:11:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb37da83-49c9-4b45-aa3d-a5e586b87540","html_url":"https://github.com/phpseclib/phpseclib3_rector","commit_stats":null,"previous_names":["phpseclib/phpseclib3_rector"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/phpseclib/phpseclib3_rector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpseclib%2Fphpseclib3_rector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpseclib%2Fphpseclib3_rector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpseclib%2Fphpseclib3_rector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpseclib%2Fphpseclib3_rector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpseclib","download_url":"https://codeload.github.com/phpseclib/phpseclib3_rector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpseclib%2Fphpseclib3_rector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29998079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T09:59:02.300Z","status":"ssl_error","status_checked_at":"2026-03-02T09:59:02.001Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-28T10:10:30.717Z","updated_at":"2026-03-02T10:02:31.874Z","avatar_url":"https://github.com/phpseclib.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phpseclib3_rector\n\nRector rules to upgrade a phpseclib v2.0 install to phpseclib v3.0\n\n## Overview\n\nYou can use [phpseclib2_compat](https://github.com/phpseclib/phpseclib2_compat) to make all your phpseclib v2.0 calls use phpseclib v3.0, internally, under the hood, or you can use this [Rector](https://getrector.com/) rule to upgrade your phpseclib v2.0 calls to phpseclib v3.0 calls.\n\n## Installation\n\nWith [Composer](https://getcomposer.org/):\n\n```\ncomposer require phpseclib/phpseclib3_rector:~1.0\n```\n\n## Usage\n\nCreate a rector.php file with the following contents:\n\n```php\n\u003c?php\nuse Rector\\Config\\RectorConfig;\nuse phpseclib\\phpseclib3Rector\\Set;\n\nreturn RectorConfig::configure()\n    -\u003ewithSets([Set::PATH]);\n```\nIn the same directory where you created that file you can then run Rector by doing either of these commands:\n\n```\nvendor/bin/rector process src --dry-run\nvendor/bin/rector process src\n```\nThe files in the `src/` directory will either be full on modified or (in the case of `--dry-run`) the changes that would be made will be previewed.\n\n## Running the tests\n\nTo run all Retor tests, run\n\n```\nvendor/bin/phpunit tests\n```\n\nTo run all tests of a single rector rule, add --filter to the test command.\n\n```\nvendor/bin/phpunit tests --filter CustomRectorTest\n```\n\n### Test Fixtures\n\nNext to the test case, there is `/Fixture` directory. It contains many test fixture files that verified the Rector rule work correctly in all possible cases.\n\nThere are 2 fixture formats:\n\nA. `test_fixture.php.inc` - The Code Should Change\n\n```php\n\u003ccode before\u003e\n-----\n\u003ccode after\u003e'\n```\n\nB. `skip_rule_test_fixture.php.inc` - The Code Should Be Skipped\n\n```php\n\u003ccode before\u003e\n```\n\n## Rules\n\n### Public Key Loader\n\nThis rule is for `v2` -\u003e `v3` upgrade.\n\nThis rule helps to load unencrypted and encrypted public / private keys.\n\nIn `v2` `loadKey()` returns true on success and false on failure. `v2` only supports RSA keys and `$rsa` is *not* immutable.\nAnd in `v3` `PublicKeyLoader` returns an immutable instance of either `\\phpseclib3\\Crypt\\Common\\PublicKey` or\n`\\phpseclib3\\Crypt\\Common\\PrivateKey`. An exception is thrown on failure.\n\nIt replaces\n```php\nuse phpseclib\\Crypt\\RSA;\n\n$rsa = new RSA();\n$rsa-\u003eloadKey('...');\n```\nwith\n\n```php\nuse phpseclib3\\Crypt\\PublicKeyLoader;\n\n$rsa = PublicKeyLoader::load('...');\n```\n\nWhen `setPassword` is used, `$rsa-\u003esetPassword('password');` will be replaced with `$rsa = PublicKeyLoader::load('...', $password);`.\n\nAdditionally it replaces the following methods:\n\n|               v2              |                   v3                  |\n|-------------------------------|---------------------------------------|\n| $rsa-\u003egetSize()               | $rsa-\u003egetLength()                     |\n| $rsa-\u003esetHash('sha256');      | $rsa = $rsa-\u003ewithHash('sha256')       |\n| $rsa-\u003esetMGFHash('sha256');   | $rsa = $rsa-\u003ewithMGFHash('sha256')    |\n| $rsa-\u003esetSaltLength(10);      | $rsa-\u003ewithSaltLength(10)              |\n| $rsa-\u003esetSignatureMode(RSA::SIGNATURE_PKCS1);     | $rsa-\u003ewithPadding(RSA::SIGNATURE_PKCS1);  |\n| $rsa-\u003esetEncryptionMode(RSA::ENCRYPTION_PKCS1);   | $rsa-\u003ewithPadding(RSA::ENCYRPTION_PKCS1); |\n| $rsa-\u003esetEncryptionMode(RSA::ENCRYPTION_PKCS1); $rsa-\u003esetSignatureMode(RSA::SIGNATURE_PKCS1); | $rsa-\u003ewithPadding(RSA::SIGNATURE_PKCS1 | RSA::ENCYRPTION_PKCS1);|\n\n### Public Key Loader Chained\n\nDoes the same things as `PublicKeyLoader`, but chains the methods.\n\nThe chaining option writes everything into _one_ line.\nYou can format them by running:\n\n```sh\nvendor/bin/php-cs-fixer fix path/to/file.php --rules=binary_operator_spaces,method_chaining_indentation\n```\n\n### Create Key\n\nThis rule is for `v2` -\u003e `v3` upgrade.\n\nIt replaces\n```php\nuse phpseclib\\Crypt\\RSA;\n\n$rsa = new RSA();\nextract($rsa-\u003ecreateKey(2048));\n```\n\nwith\n\n```php\nuse phpseclib3\\Crypt\\RSA;\n\n$privateKey = RSA::createKey(2048);\n$publicKey = $privateKey-\u003egetPublicKey();\n$privateKey = (string) $privateKey;\n$publicKey = (string) $publicKey;\n```\n\nIn `v2`, `$rsa-\u003ecreateKey()` returns an array with 3x parameters: `privatekey`, `publickey`, `partial`.\n`privatekey` and `public key` are strings, partial can be ignored.\n\nThe above `v3` example returns an immutable instance of `phpseclib3\\Crypt\\Common\\PrivateKey`.\n\nThe public key can be extracted by: `$rsa-\u003egetPublicKey()`.\n\n### HashLength\n\nThis rule is for `v2` -\u003e `v3` upgrade.\n\nIn phpseclib `v2` getLength would sometimes return the length in bits and sometimes it'd return the length in bytes\nin phpseclib `v3` it was made consistent -\ngetLength always returns the length in bits and getLengthInBytes always returns the length in bytes.\n\nIt replaces\n```php\nuse phpseclib\\Crypt\\Hash;\n\n$hash = new Hash('sha512/224');\necho $hash-\u003egetLength();\n```\nwith\n```php\nuse phpseclib3\\Crypt\\Hash;\n\n$hash = new Hash('sha512/224');\necho $hash-\u003egetLengthInBytes();\n```\n\n### SFTP File Size\n\nThis rule is for `v2` -\u003e `v3` upgrade.\n\nIn phpseclib `v2` you have filemtime, fileatime, fileowner but, instead of filesize, you just have size?\nphpseclib `v3` fixes that.\n\nIt replaces\n```php\nuse phpseclib\\Net\\SFTP;\n\n$sftp = new SFTP('...');\n$sftp-\u003elogin('username', 'password');\necho $sftp-\u003esize('/path/to/filename.ext');\n```\n\nwith\n\n```php\nuse phpseclib3\\Net\\SFTP;\n\n$sftp = new SFTP('...');\n$sftp-\u003elogin('username', 'password');\necho $sftp-\u003efilesize('/path/to/filename.ext');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpseclib%2Fphpseclib3_rector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpseclib%2Fphpseclib3_rector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpseclib%2Fphpseclib3_rector/lists"}