Skip to content

Commit

Permalink
feat(deps): Use phpseclib/phpseclib
Browse files Browse the repository at this point in the history
  • Loading branch information
ging-dev committed Jul 8, 2024
1 parent fa4e9fb commit b9604ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"nette/utils": "^4.0",
"eventsauce/object-hydrator": "^1.4",
"symfony/options-resolver": "^7.1",
"symfony/dom-crawler": "^7.1"
"symfony/dom-crawler": "^7.1",
"phpseclib/phpseclib": "~2.0"
},
"require-dev": {
"php-http/curl-client": "^2.3",
Expand Down
6 changes: 1 addition & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$length of function str_split expects int\\<1, max\\>, int given\\.$#"
count: 1
path: src/Encryption/Encrypter.php
ignoreErrors: []
30 changes: 9 additions & 21 deletions src/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,24 @@

namespace IPay\Encryption;

const IPAY_PUBLIC_KEY = <<<PUB
use phpseclib\Crypt\RSA;

final class Encrypter
{
private const IPAY_PUBLIC_KEY = <<<PUBLIC
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLenQHmHpaqYX4IrRVM8H1uB21
xWuY+clsvn79pMUYR2KwIEfeHcnZFFshjDs3D2ae4KprjkOFZPYzEWzakg2nOIUV
WO+Q6RlAU1+1fxgTvEXi4z7yi+n0Zs0puOycrm8i67jsQfHi+HgdMxCaKzHvbECr
+JWnLxnEl6615hEeMQIDAQAB
-----END PUBLIC KEY-----
PUB;
PUBLIC;

class Encrypter
{
public static function encrypt(string $message): string
{
$mlen = strlen($message);

$result = '';
foreach (str_split(
$message,
(int) ceil($mlen / ceil($mlen / 86))
) as $part) {
openssl_public_encrypt(
$part,
$part,
IPAY_PUBLIC_KEY,
OPENSSL_PKCS1_OAEP_PADDING
);

$result .= $part;
}
$rsa = new RSA();
$rsa->loadKey(static::IPAY_PUBLIC_KEY);

return base64_encode($result);
return base64_encode($rsa->encrypt($message));
}
}

0 comments on commit b9604ef

Please sign in to comment.