summary refs log tree commit diff
path: root/crypto/src/x509/X509Certificate.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/x509/X509Certificate.cs')
-rw-r--r--crypto/src/x509/X509Certificate.cs23
1 files changed, 16 insertions, 7 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index d8d97ec5e..b4e1c17f8 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -29,6 +29,8 @@ namespace Org.BouncyCastle.X509
         private readonly X509CertificateStructure c;
         //private Hashtable pkcs12Attributes = Platform.CreateHashtable();
         //private ArrayList pkcs12Ordering = Platform.CreateArrayList();
+        private readonly string sigAlgName;
+        private readonly byte[] sigAlgParams;
 		private readonly BasicConstraints basicConstraints;
 		private readonly bool[] keyUsage;
 
@@ -47,6 +49,18 @@ namespace Org.BouncyCastle.X509
 		{
 			this.c = c;
 
+            try
+            {
+                this.sigAlgName = X509SignatureUtilities.GetSignatureName(c.SignatureAlgorithm);
+
+                Asn1Encodable parameters = c.SignatureAlgorithm.Parameters;
+                this.sigAlgParams = (null == parameters) ? null : parameters.GetEncoded(Asn1Encodable.Der);
+            }
+            catch (Exception e)
+            {
+                throw new CrlException("Certificate contents invalid: " + e);
+            }
+
 			try
 			{
 				Asn1OctetString str = this.GetExtensionValue(new DerObjectIdentifier("2.5.29.19"));
@@ -249,7 +263,7 @@ namespace Org.BouncyCastle.X509
 		/// <returns>A sting representing the signature algorithm.</returns>
 		public virtual string SigAlgName
 		{
-            get { return SignerUtilities.GetEncodingName(c.SignatureAlgorithm.Algorithm); }
+            get { return sigAlgName; }
 		}
 
 		/// <summary>
@@ -267,12 +281,7 @@ namespace Org.BouncyCastle.X509
 		/// <returns>A byte array containing the Der encoded version of the parameters or null if there are none.</returns>
 		public virtual byte[] GetSigAlgParams()
 		{
-			if (c.SignatureAlgorithm.Parameters != null)
-			{
-				return c.SignatureAlgorithm.Parameters.GetDerEncoded();
-			}
-
-			return null;
+            return Arrays.Clone(sigAlgParams);
 		}
 
 		/// <summary>