Skip to content

Commit

Permalink
Add RSASSA-PSS support to CryptoTypes (#51)
Browse files Browse the repository at this point in the history
Implemented support for the RSASSA-PSS encryption algorithm by adding its OID to AlgorithmIdentifier class. Also, updated the method that determines private key type in OneAsymmetricKey class to recognize RSASSA-PSS encryption. This ensures compatibility with more diverse RSA key types.
  • Loading branch information
Spomky authored Mar 30, 2024
1 parent 873f750 commit 2547e68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ abstract class AlgorithmIdentifier implements AlgorithmIdentifierType

final public const OID_SHA1_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.5';

final public const OID_RSASSA_PSS_ENCRYPTION = '1.2.840.113549.1.1.10';

final public const OID_SHA256_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.11';

final public const OID_SHA384_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.12';
Expand Down
6 changes: 4 additions & 2 deletions src/CryptoTypes/Asymmetric/OneAsymmetricKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ public function privateKey(): PrivateKey
{
$algo = $this->algorithmIdentifier();
switch ($algo->oid()) {
// RSA
// RSA (including RSASSA-PSS)
case AlgorithmIdentifier::OID_RSA_ENCRYPTION:
case AlgorithmIdentifier::OID_RSASSA_PSS_ENCRYPTION:
return RSAPrivateKey::fromDER($this->privateKeyData);
// elliptic curve
case AlgorithmIdentifier::OID_EC_PUBLIC_KEY:
Expand Down Expand Up @@ -225,8 +226,9 @@ public function privateKey(): PrivateKey
return X448PrivateKey::fromOctetString(OctetString::fromDER($this->privateKeyData), $pubkey)
->withVersion($this->version)
->withAttributes($this->attributes);
default:
throw new RuntimeException('Private key ' . $algo->name() . ' not supported.');
}
throw new RuntimeException('Private key ' . $algo->name() . ' not supported.');
}

/**
Expand Down

0 comments on commit 2547e68

Please sign in to comment.