Skip to content

Commit 6b701b2

Browse files
committed
MEthod name correction.
1 parent 27b4bdb commit 6b701b2

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/Org.Security.Cryptography.X509Extensions/X509AsymmetricAlgorithmExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static class X509AsymmetricAlgorithmExtensions
1010
/// <summary>
1111
/// Returns an AsymmetricAlgorithm, representing the PublicKey
1212
/// </summary>
13-
internal static AsymmetricAlgorithm GetRsaPublicKeyAsymmetricAlgorithm(this X509Certificate2 x509Cert)
13+
internal static AsymmetricAlgorithm GetPublicKeyAsymmetricAlgorithm(this X509Certificate2 x509Cert)
1414
{
1515
if (null == x509Cert) throw new ArgumentNullException(nameof(x509Cert));
1616
if (null == x509Cert.Thumbprint) throw new ArgumentNullException("X509Certificate2.Thumbprint was NULL.");
@@ -38,7 +38,7 @@ internal static AsymmetricAlgorithm GetRsaPublicKeyAsymmetricAlgorithm(this X509
3838
/// <summary>
3939
/// Returns an AsymmetricAlgorithm, representing the PrivateKey
4040
/// </summary>
41-
internal static AsymmetricAlgorithm GetRsaPrivateKeyAsymmetricAlgorithm(this X509Certificate2 x509Cert)
41+
internal static AsymmetricAlgorithm GetPrivateKeyAsymmetricAlgorithm(this X509Certificate2 x509Cert)
4242
{
4343
if (null == x509Cert) throw new ArgumentNullException(nameof(x509Cert));
4444
if (null == x509Cert.Thumbprint) throw new ArgumentNullException("X509Certificate2.Thumbprint was NULL.");

src/Org.Security.Cryptography.X509Extensions/X509SignatureExtensions.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@ namespace Org.Security.Cryptography
77
{
88
public static class X509SignatureExtensions
99
{
10-
public static byte[] CreateSignature(this X509Certificate2 x509Cert, byte[] hash)
10+
/// <summary>
11+
/// Signs given messageDigest (hash-value) using X509 PrivateKey and returns the RSA PKCS #1 signature.
12+
/// </summary>
13+
public static byte[] CreateSignature(this X509Certificate2 x509Cert, byte[] messageDigest)
1114
{
1215
if (null == x509Cert) throw new ArgumentNullException(nameof(x509Cert));
13-
if (null == hash) throw new ArgumentNullException(nameof(hash));
16+
if (null == messageDigest) throw new ArgumentNullException(nameof(messageDigest));
1417

15-
var asymmetricAlgorithm = x509Cert.GetRsaPrivateKeyAsymmetricAlgorithm();
16-
var hashAlgorithmName = InferHashAlgorithm(hash);
18+
var asymmetricAlgorithm = x509Cert.GetPrivateKeyAsymmetricAlgorithm();
19+
var hashAlgorithmName = InferHashAlgorithm(messageDigest);
1720

1821
var formatter = new RSAPKCS1SignatureFormatter(asymmetricAlgorithm);
1922
formatter.SetHashAlgorithm(hashAlgorithmName);
2023

21-
return formatter.CreateSignature(hash);
24+
return formatter.CreateSignature(messageDigest);
2225
}
2326

27+
/// <summary>
28+
/// Verifies RSA PKCS #1 signature for give messageDigest (hash-value), using X509 PublicKey.
29+
/// Returns true|false indicating if the signature is valid.
30+
/// </summary>
2431
public static bool VerifySignature(this X509Certificate2 x509Cert, byte[] hash, byte[] signature)
2532
{
2633
if (null == x509Cert) throw new ArgumentNullException(nameof(x509Cert));
2734
if (null == hash) throw new ArgumentNullException(nameof(hash));
2835
if (null == signature) throw new ArgumentNullException(nameof(signature));
2936

30-
var asymmetricAlgorithm = x509Cert.GetRsaPublicKeyAsymmetricAlgorithm();
37+
var asymmetricAlgorithm = x509Cert.GetPublicKeyAsymmetricAlgorithm();
3138
var hashAlgorithmName = InferHashAlgorithm(hash);
3239

3340
var formatter = new RSAPKCS1SignatureDeformatter(asymmetricAlgorithm);
@@ -55,7 +62,7 @@ static string InferHashAlgorithm(byte[] hash)
5562
case 48: return HashAlgorithmName.SHA384.Name;
5663
case 64: return HashAlgorithmName.SHA512.Name;
5764
default:
58-
throw new Exception($"Can't infer Hash algorithm. Unexpected hash length {hash.Length:#,0} bytes. Expecting 16|20|32|48|64 bytes.");
65+
throw new Exception($"Can't infer HashAlgorithm. Unknown hash length {hash.Length:#,0} bytes. Expecting 16|20|32|48|64 bytes.");
5966
}
6067
}
6168
}

src/Org.Security.Cryptography.X509Extensions/X509StreamEncryptionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void EncryptStream(this X509Certificate2 x509Cert, Stream inputStr
3232
// Encrypt using Public key.
3333
// DO NOT Dispose this; Doing so will render the X509Certificate in the cache use-less.
3434
// Did endurance test of 1 mil cycles, found NO HANDLE leak.
35-
var keyEncryption = x509Cert.GetRsaPublicKeyAsymmetricAlgorithm();
35+
var keyEncryption = x509Cert.GetPublicKeyAsymmetricAlgorithm();
3636

3737
using (var dataEncryption = SymmetricAlgorithm.Create(dataEncryptionAlgorithmName))
3838
{
@@ -60,7 +60,7 @@ public static void DecryptStream(this X509Certificate2 x509Cert, Stream inputStr
6060
// Decrypt using Private key.
6161
// DO NOT Dispose this; Doing so will render the X509Certificate in cache use-less.
6262
// Did endurance test of 1 mil cycles, found NO HANDLE leak.
63-
var keyEncryption = x509Cert.GetRsaPrivateKeyAsymmetricAlgorithm();
63+
var keyEncryption = x509Cert.GetPrivateKeyAsymmetricAlgorithm();
6464

6565
using (var dataEncryption = SymmetricAlgorithm.Create(dataEncryptionAlgorithmName))
6666
{

0 commit comments

Comments
 (0)