File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 3
3
namespace MiladRahimi \Jwt \Cryptography \Keys ;
4
4
5
5
use MiladRahimi \Jwt \Exceptions \InvalidKeyException ;
6
+ use Throwable ;
6
7
7
8
/**
8
9
* Class RsaPrivateKey
@@ -25,11 +26,18 @@ class RsaPrivateKey
25
26
*/
26
27
public function __construct (string $ filePath , $ passphrase = '' )
27
28
{
28
- $ this ->resource = openssl_pkey_get_private ('file:/// ' . $ filePath , $ passphrase );
29
+ try {
30
+ $ this ->resource = openssl_pkey_get_private (file_get_contents (realpath ($ filePath )), $ passphrase );
29
31
30
- if (empty ($ this ->resource )) {
31
- throw new InvalidKeyException ();
32
+ if (empty ($ this ->resource )) {
33
+ throw new InvalidKeyException ();
34
+ }
35
+ } catch (InvalidKeyException $ e ) {
36
+ throw $ e ;
37
+ } catch (Throwable $ e ) {
38
+ throw new InvalidKeyException ('Failed to read the key. ' , 0 , $ e );
32
39
}
40
+
33
41
}
34
42
35
43
/**
Original file line number Diff line number Diff line change 3
3
namespace MiladRahimi \Jwt \Cryptography \Keys ;
4
4
5
5
use MiladRahimi \Jwt \Exceptions \InvalidKeyException ;
6
+ use Throwable ;
6
7
7
8
/**
8
9
* Class RsaPublicKey
@@ -24,10 +25,16 @@ class RsaPublicKey
24
25
*/
25
26
public function __construct (string $ filePath )
26
27
{
27
- $ this ->resource = openssl_pkey_get_public ('file:/// ' . $ filePath );
28
+ try {
29
+ $ this ->resource = openssl_pkey_get_public (file_get_contents (realpath ($ filePath )));
28
30
29
- if (empty ($ this ->resource )) {
30
- throw new InvalidKeyException ();
31
+ if (empty ($ this ->resource )) {
32
+ throw new InvalidKeyException ();
33
+ }
34
+ } catch (InvalidKeyException $ e ) {
35
+ throw $ e ;
36
+ } catch (Throwable $ e ) {
37
+ throw new InvalidKeyException ('Failed to read the key. ' , 0 , $ e );
31
38
}
32
39
}
33
40
You can’t perform that action at this time.
0 commit comments