mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathX509SignatureUtil.cs
More file actions
96 lines (75 loc) · 3.49 KB
/
Copy pathX509SignatureUtil.cs
File metadata and controls
96 lines (75 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.CryptoPro;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Oiw;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.Rosstandart;
using Org.BouncyCastle.Asn1.TeleTrust;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.X509
{
internal class X509SignatureUtilities
{
/// <summary>
/// Return the digest algorithm using one of the standard JCA string representations rather than the algorithm
/// identifier (if possible).
/// </summary>
private static string GetDigestName(DerObjectIdentifier digestAlgOid)
{
/*
* Note that this can't simply redirect to DigestUtilities because I think the Asn1Signature stuff
* depends on particular digest names in some cases (e.g. non-hyphenated SHA algorithms).
*/
if (PkcsObjectIdentifiers.MD5.Equals(digestAlgOid))
return "MD5";
if (OiwObjectIdentifiers.IdSha1.Equals(digestAlgOid))
return "SHA1";
if (NistObjectIdentifiers.IdSha224.Equals(digestAlgOid))
return "SHA224";
if (NistObjectIdentifiers.IdSha256.Equals(digestAlgOid))
return "SHA256";
if (NistObjectIdentifiers.IdSha384.Equals(digestAlgOid))
return "SHA384";
if (NistObjectIdentifiers.IdSha512.Equals(digestAlgOid))
return "SHA512";
if (NistObjectIdentifiers.IdSha512_224.Equals(digestAlgOid))
return "SHA512(224)";
if (NistObjectIdentifiers.IdSha512_256.Equals(digestAlgOid))
return "SHA512(256)";
if (TeleTrusTObjectIdentifiers.RipeMD128.Equals(digestAlgOid))
return "RIPEMD128";
if (TeleTrusTObjectIdentifiers.RipeMD160.Equals(digestAlgOid))
return "RIPEMD160";
if (TeleTrusTObjectIdentifiers.RipeMD256.Equals(digestAlgOid))
return "RIPEMD256";
if (CryptoProObjectIdentifiers.GostR3411.Equals(digestAlgOid))
return "GOST3411";
if (RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256.Equals(digestAlgOid))
return "GOST3411-2012-256";
if (RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512.Equals(digestAlgOid))
return "GOST3411-2012-512";
return digestAlgOid.GetID();
}
internal static string GetSignatureName(AlgorithmIdentifier sigAlgID)
{
DerObjectIdentifier sigAlgOid = sigAlgID.Algorithm;
Asn1Encodable sigAlgParams = sigAlgID.Parameters;
if (!X509Utilities.IsAbsentParameters(sigAlgParams))
{
if (PkcsObjectIdentifiers.IdRsassaPss.Equals(sigAlgOid))
{
var rsassaPssParameters = RsassaPssParameters.GetInstance(sigAlgParams);
return GetDigestName(rsassaPssParameters.HashAlgorithm.Algorithm) + "withRSAandMGF1";
}
if (X9ObjectIdentifiers.ECDsaWithSha2.Equals(sigAlgOid))
{
AlgorithmIdentifier ecDsaParams = AlgorithmIdentifier.GetInstance(sigAlgParams);
return GetDigestName(ecDsaParams.Algorithm) + "withECDSA";
}
}
return SignerUtilities.GetEncodingName(sigAlgOid) ?? sigAlgOid.GetID();
}
}
}