private static ICollection GetAlternativeName( Asn1OctetString extVal) { IList temp = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(); if (extVal != null) { try { Asn1Sequence seq = DerSequence.GetInstance(FromExtensionValue(extVal)); foreach (Asn1Encodable primName in seq) { IList list = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(); GeneralName genName = GeneralName.GetInstance(primName); list.Add(genName.TagNo); switch (genName.TagNo) { case GeneralName.EdiPartyName: case GeneralName.X400Address: case GeneralName.OtherName: list.Add(genName.Name.ToAsn1Object()); break; case GeneralName.DirectoryName: list.Add(X509Name.GetInstance(genName.Name).ToString()); break; case GeneralName.DnsName: case GeneralName.Rfc822Name: case GeneralName.UniformResourceIdentifier: list.Add(((IAsn1String)genName.Name).GetString()); break; case GeneralName.RegisteredID: list.Add(DerObjectIdentifier.GetInstance(genName.Name).Id); break; case GeneralName.IPAddress: list.Add(DerOctetString.GetInstance(genName.Name).GetOctets()); break; default: throw new IOException("Bad tag number: " + genName.TagNo); } temp.Add(list); } } catch (Exception e) { throw new CertificateParsingException(e.Message); } } return(temp); }
internal static ICollection GetAlternativeName( byte[] extVal) { IList temp = Platform.CreateArrayList(); if (extVal != null) { try { Asn1Sequence seq = Asn1Sequence.GetInstance(extVal); foreach (GeneralName genName in seq) { IList list = Platform.CreateArrayList(); list.Add(genName.TagNo); switch (genName.TagNo) { case GeneralName.EdiPartyName: case GeneralName.X400Address: case GeneralName.OtherName: list.Add(genName.Name.ToAsn1Object()); break; case GeneralName.DirectoryName: list.Add(X500Name.GetInstance(genName.Name).ToString()); break; case GeneralName.DnsName: case GeneralName.Rfc822Name: case GeneralName.UniformResourceIdentifier: list.Add(((IAsn1String)genName.Name).GetString()); break; case GeneralName.RegisteredID: list.Add(DerObjectIdentifier.GetInstance(genName.Name).Id); break; case GeneralName.IPAddress: list.Add(DerOctetString.GetInstance(genName.Name).GetOctets()); break; default: throw new IOException("Bad tag number: " + genName.TagNo); } temp.Add(list); } } catch (Exception e) { throw new CertificateParsingException(e.Message); } } return(temp); }
/** * Constructor from Asn1Sequence. * <p/> * The sequence is of type CertHash: * <p/> * <pre> * CertHash ::= SEQUENCE { * hashAlgorithm AlgorithmIdentifier, * certificateHash OCTET STRING * } * </pre> * * @param seq The ASN.1 sequence. */ private CertHash( Asn1Sequence seq) { if (seq.Count != 2) { throw new ArgumentException("Bad sequence size: " + seq.Count); } this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]); this.certificateHash = DerOctetString.GetInstance(seq[1]).GetOctets(); }
public SignerInfo( Asn1Sequence seq) { IEnumerator e = seq.GetEnumerator(); e.MoveNext(); version = (DerInteger)e.Current; e.MoveNext(); sid = SignerIdentifier.GetInstance(e.Current); e.MoveNext(); digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current); e.MoveNext(); object obj = e.Current; if (obj is Asn1TaggedObject) { authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)obj, false); e.MoveNext(); digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current); } else { authenticatedAttributes = null; digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(obj); } e.MoveNext(); encryptedDigest = DerOctetString.GetInstance(e.Current); if (e.MoveNext()) { unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current, false); } else { unauthenticatedAttributes = null; } }
internal static IParameters <Algorithm> GetCipherParameters(AlgorithmIdentifier encScheme) { DerObjectIdentifier encSchemeAlg = encScheme.Algorithm; if (encSchemeAlg.On(NistObjectIdentifiers.Aes)) { if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Ecb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Ecb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Ecb)) { return(FipsAes.Ecb); } if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Cbc) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Cbc) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Cbc)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(FipsAes.Cbc.WithIV(iv)); } if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Cfb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Cfb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Cfb)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(FipsAes.Cfb128.WithIV(iv)); } if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Ofb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Ofb) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Ofb)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(FipsAes.Ofb.WithIV(iv)); } if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Ccm) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Ccm) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Ccm)) { CcmParameters authParams = CcmParameters.GetInstance(encScheme.Parameters); return(FipsAes.Ccm.WithIV(authParams.GetNonce()).WithMacSize(authParams.IcvLen * 8)); } if (encSchemeAlg.Equals(NistObjectIdentifiers.IdAes128Gcm) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes192Gcm) || encSchemeAlg.Equals(NistObjectIdentifiers.IdAes256Gcm)) { GcmParameters authParams = GcmParameters.GetInstance(encScheme.Parameters); return(FipsAes.Ccm.WithIV(authParams.GetNonce()).WithMacSize(authParams.IcvLen * 8)); } } if (encSchemeAlg.Equals(NttObjectIdentifiers.IdCamellia128Cbc) || encSchemeAlg.Equals(NttObjectIdentifiers.IdCamellia192Cbc) || encSchemeAlg.Equals(NttObjectIdentifiers.IdCamellia256Cbc)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(Camellia.Cbc.WithIV(iv)); } if (encSchemeAlg.Equals(PkcsObjectIdentifiers.DesEde3Cbc)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(FipsTripleDes.Cbc.WithIV(iv)); } if (encSchemeAlg.Equals(KisaObjectIdentifiers.IdSeedCbc)) { byte[] iv = DerOctetString.GetInstance(encScheme.Parameters).GetOctets(); return(Seed.Cbc.WithIV(iv)); } throw new ArgumentException("cannot match algorithm"); }