<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0-beta.98" />

X509SignatureUtilities

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 { private static string GetDigestName(DerObjectIdentifier digestAlgOid) { 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 algorithm = sigAlgID.Algorithm; Asn1Encodable parameters = sigAlgID.Parameters; if (!X509Utilities.IsAbsentParameters(parameters)) { if (PkcsObjectIdentifiers.IdRsassaPss.Equals(algorithm)) return GetDigestName(RsassaPssParameters.GetInstance(parameters).HashAlgorithm.Algorithm) + "withRSAandMGF1"; if (X9ObjectIdentifiers.ECDsaWithSha2.Equals(algorithm)) return GetDigestName(AlgorithmIdentifier.GetInstance(parameters).Algorithm) + "withECDSA"; } return SignerUtilities.GetEncodingName(algorithm) ?? algorithm.GetID(); } } }