GetAlgorithmOid() статический приватный Метод

static private GetAlgorithmOid ( string algorithmName ) : DerObjectIdentifier
algorithmName string
Результат Org.BouncyCastle.Asn1.DerObjectIdentifier
Пример #1
0
 public OcspReq Generate(string signingAlgorithm, AsymmetricKeyParameter privateKey, X509Certificate[] chain, SecureRandom random)
 {
     //IL_0008: Unknown result type (might be due to invalid IL or missing references)
     //IL_002f: Unknown result type (might be due to invalid IL or missing references)
     if (signingAlgorithm == null)
     {
         throw new ArgumentException("no signing algorithm specified");
     }
     try
     {
         DerObjectIdentifier algorithmOid = OcspUtilities.GetAlgorithmOid(signingAlgorithm);
         return(GenerateRequest(algorithmOid, privateKey, chain, random));
     }
     catch (ArgumentException)
     {
         throw new ArgumentException("unknown signing algorithm specified: " + signingAlgorithm);
     }
 }
Пример #2
0
        public OcspReq Generate(string signingAlgorithm, AsymmetricKeyParameter privateKey, X509Certificate[] chain, SecureRandom random)
        {
            if (signingAlgorithm == null)
            {
                throw new ArgumentException("no signing algorithm specified");
            }
            OcspReq result;

            try
            {
                DerObjectIdentifier algorithmOid = OcspUtilities.GetAlgorithmOid(signingAlgorithm);
                result = this.GenerateRequest(algorithmOid, privateKey, chain, random);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException("unknown signing algorithm specified: " + signingAlgorithm);
            }
            return(result);
        }
        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)));
        }
        private BasicOcspResp GenerateResponse(
            string signatureName,
            AsymmetricKeyParameter privateKey,
            X509Certificate[]               chain,
            DateTime producedAt,
            SecureRandom random)
        {
            DerObjectIdentifier signingAlgorithm;

            try
            {
                signingAlgorithm = OcspUtilities.GetAlgorithmOid(signatureName);
            }
            catch (Exception e)
            {
                throw new ArgumentException("unknown signing algorithm specified", "signatureName", e);
            }

            Asn1EncodableVector responses = new Asn1EncodableVector();

            foreach (ResponseObject respObj in list)
            {
                try
                {
                    responses.Add(respObj.ToResponse());
                }
                catch (Exception e)
                {
                    throw new OcspException("exception creating Request", e);
                }
            }

            ResponseData tbsResp = new ResponseData(responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(responses), responseExtensions);

            ISigner sig = null;

            try
            {
                sig = SignerUtilities.GetSigner(signatureName);

                if (random != null)
                {
                    sig.Init(true, new ParametersWithRandom(privateKey, random));
                }
                else
                {
                    sig.Init(true, privateKey);
                }
            }
            catch (Exception e)
            {
                throw new OcspException("exception creating signature: " + e, e);
            }

            DerBitString bitSig = null;

            try
            {
                byte[] encoded = tbsResp.GetDerEncoded();
                sig.BlockUpdate(encoded, 0, encoded.Length);

                bitSig = new DerBitString(sig.GenerateSignature());
            }
            catch (Exception e)
            {
                throw new OcspException("exception processing TBSRequest: " + e, e);
            }

            AlgorithmIdentifier sigAlgId = OcspUtilities.GetSigAlgID(signingAlgorithm);

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector v = new Asn1EncodableVector();
                try
                {
                    for (int i = 0; i != chain.Length; i++)
                    {
                        v.Add(
                            X509CertificateStructure.GetInstance(
                                Asn1Object.FromByteArray(chain[i].GetEncoded())));
                    }
                }
                catch (IOException e)
                {
                    throw new OcspException("error processing certs", e);
                }
                catch (CertificateEncodingException e)
                {
                    throw new OcspException("error encoding certs", e);
                }

                return(new BasicOcspResp(new BasicOcspResponse(tbsResp, sigAlgId, bitSig, new DerSequence(v))));
            }
            else
            {
                return(new BasicOcspResp(new BasicOcspResponse(tbsResp, sigAlgId, bitSig, null)));
            }
        }