Org.BouncyCastle.Ocsp.OcspUtilities.GetSigAlgID C# (CSharp) Method

GetSigAlgID() static private method

static private GetSigAlgID ( DerObjectIdentifier sigOid ) : AlgorithmIdentifier
sigOid Org.BouncyCastle.Asn1.DerObjectIdentifier
return Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier
		internal static AlgorithmIdentifier GetSigAlgID(
			DerObjectIdentifier sigOid)
		{
			if (noParams.Contains(sigOid))
			{
				return new AlgorithmIdentifier(sigOid);
			}

			return new AlgorithmIdentifier(sigOid, DerNull.Instance);
		}

Usage Example

        private BasicOcspResp GenerateResponse(string signatureName, AsymmetricKeyParameter privateKey, X509Certificate[] chain, DateTime producedAt, SecureRandom random)
        {
            DerObjectIdentifier algorithmOid;

            try
            {
                algorithmOid = OcspUtilities.GetAlgorithmOid(signatureName);
            }
            catch (Exception innerException)
            {
                throw new ArgumentException("unknown signing algorithm specified", innerException);
            }
            Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(new Asn1Encodable[0]);

            foreach (BasicOcspRespGenerator.ResponseObject responseObject in this.list)
            {
                try
                {
                    asn1EncodableVector.Add(new Asn1Encodable[]
                    {
                        responseObject.ToResponse()
                    });
                }
                catch (Exception e)
                {
                    throw new OcspException("exception creating Request", e);
                }
            }
            ResponseData responseData = new ResponseData(this.responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(asn1EncodableVector), this.responseExtensions);
            ISigner      signer       = null;

            try
            {
                signer = SignerUtilities.GetSigner(signatureName);
                if (random != null)
                {
                    signer.Init(true, new ParametersWithRandom(privateKey, random));
                }
                else
                {
                    signer.Init(true, privateKey);
                }
            }
            catch (Exception ex)
            {
                throw new OcspException("exception creating signature: " + ex, ex);
            }
            DerBitString signature = null;

            try
            {
                byte[] derEncoded = responseData.GetDerEncoded();
                signer.BlockUpdate(derEncoded, 0, derEncoded.Length);
                signature = new DerBitString(signer.GenerateSignature());
            }
            catch (Exception ex2)
            {
                throw new OcspException("exception processing TBSRequest: " + ex2, ex2);
            }
            AlgorithmIdentifier sigAlgID = OcspUtilities.GetSigAlgID(algorithmOid);
            DerSequence         certs    = null;

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(new Asn1Encodable[0]);
                try
                {
                    for (int num = 0; num != chain.Length; num++)
                    {
                        asn1EncodableVector2.Add(new Asn1Encodable[]
                        {
                            X509CertificateStructure.GetInstance(Asn1Object.FromByteArray(chain[num].GetEncoded()))
                        });
                    }
                }
                catch (IOException e2)
                {
                    throw new OcspException("error processing certs", e2);
                }
                catch (CertificateEncodingException e3)
                {
                    throw new OcspException("error encoding certs", e3);
                }
                certs = new DerSequence(asn1EncodableVector2);
            }
            return(new BasicOcspResp(new BasicOcspResponse(responseData, sigAlgID, signature, certs)));
        }
All Usage Examples Of Org.BouncyCastle.Ocsp.OcspUtilities::GetSigAlgID