public X9FieldID( DERObjectIdentifier id, BigInteger primeP) { this.id = id; this.parameters = new DERInteger(primeP); }
public PrivateKeyInfo( AlgorithmIdentifier algId, ASN1Object privateKey) { this.privKey = privateKey; this.algId = algId; }
public CertBag( ASN1Sequence seq) { this.seq = seq; this.certId = (DERObjectIdentifier)seq.getObjectAt(0); this.certValue = ((DERTaggedObject)seq.getObjectAt(1)).getObject(); }
public RSAPrivateKey(ASN1Object asn1Key) { // NOTE: currently only supporting PKCS#1 without optional OtherPrimeInfos var keySeq = asn1Key as ASN1Sequence; SecurityAssert.NotNull(keySeq); SecurityAssert.Assert(keySeq !.Count == 9); Modulus = GetInteger(keySeq, 1); var publicExponent = GetInteger(keySeq, 2); Exponent = GetInteger(keySeq, 3); var prime1 = GetInteger(keySeq, 4); var prime2 = GetInteger(keySeq, 5); var exponent1 = GetInteger(keySeq, 6); var exponent2 = GetInteger(keySeq, 7); // TODO var coefficent = GetInteger(keySeq, 8); SecurityAssert.Assert(Modulus == prime1 * prime2); SecurityAssert.Assert(exponent1 == Exponent % (prime1 - 1)); SecurityAssert.Assert(exponent2 == Exponent % (prime2 - 1)); // TODO assert Coefficent == ((inverse of q) mod p) PublicKey = new RSAPublicKey(Modulus, publicExponent); }
public PrivateKeyInfo( ASN1Sequence seq) { IEnumerator e = seq.getObjects(); e.MoveNext(); BigInteger version = ((DERInteger)e.Current).getValue(); if (version.intValue() != 0) { throw new ArgumentException("wrong version for private key info"); } e.MoveNext(); algId = new AlgorithmIdentifier((ASN1Sequence)e.Current); try { e.MoveNext(); MemoryStream bIn = new MemoryStream(((ASN1OctetString)e.Current).getOctets()); ASN1InputStream aIn = new ASN1InputStream(bIn); privKey = aIn.readObject(); } catch (IOException) { throw new ArgumentException("Error recoverying private key from sequence"); } }
public CertBag( DERObjectIdentifier certId, ASN1Object certValue) { this.certId = certId; this.certValue = certValue; }
public SafeBag( DERObjectIdentifier oid, ASN1Object obj) { this.bagId = oid; this.bagValue = obj; this.bagAttributes = null; }
protected override void DoComponentAssign(int j, ASN1Object ulaz) { this.Components[j] = ulaz; if (this.ComponentTypes[j] is UNIQUE_TypeInfo) { this.unique_TypeInfo.uoid = Components[j] as ASN1ObjectIdentifier; } }
/** * */ public IetfAttrSyntax(ASN1Sequence seq) { int i = 0; if (seq.getObjectAt(0) is ASN1TaggedObject) { policyAuthority = GeneralNames.getInstance(((ASN1TaggedObject)seq.getObjectAt(0)), false); i++; } else if (seq.size() == 2) { // VOMS fix policyAuthority = GeneralNames.getInstance(seq.getObjectAt(0)); i++; } if (!(seq.getObjectAt(i) is ASN1Sequence)) { throw new ArgumentException("Non-IetfAttrSyntax encoding"); } seq = (ASN1Sequence)seq.getObjectAt(i); for (IEnumerator e = seq.getObjects(); e.MoveNext();) { ASN1Object obj = (ASN1Object)e.Current; int type; if (obj is DERObjectIdentifier) { type = VALUE_OID; } else if (obj is DERUTF8String) { type = VALUE_UTF8; } else if (obj is DEROctetString) { type = VALUE_OCTETS; } else { throw new ArgumentException("Bad value type encoding IetfAttrSyntax"); } if (valueChoice < 0) { valueChoice = type; } if (type != valueChoice) { throw new ArgumentException("Mix of value types in IetfAttrSyntax"); } values.Add(obj); } }
public SafeBag( DERObjectIdentifier oid, ASN1Object obj, ASN1Set bagAttributes) { this.bagId = oid; this.bagValue = obj; this.bagAttributes = bagAttributes; }
private static T GetElement <T>(ASN1Object asn1, int index) where T : ASN1Object { var obj = GetElement(asn1, index) as T; SecurityAssert.NotNull(obj); return(obj !); }
private static ASN1Set ToSet(ASN1Object asn1, int minLength = 0, int maxLength = int.MaxValue) { var seq = asn1 as ASN1Set; SecurityAssert.NotNull(seq); SecurityAssert.Assert(seq !.Count >= minLength && seq !.Count <= maxLength); return(seq); }
public SafeBag( ASN1Sequence seq) { this.bagId = (DERObjectIdentifier)seq.getObjectAt(0); this.bagValue = ((DERTaggedObject)seq.getObjectAt(1)).getObject(); if (seq.size() == 3) { this.bagAttributes = (ASN1Set)seq.getObjectAt(2); } }
public Time( ASN1Object time) { if (!(time is DERUTCTime) && !(time is DERGeneralizedTime)) { throw new ArgumentException("unknown object passed to Time"); } this.time = time; }
public DHPrivateKey(DHParameterConfig parameters, ASN1Object input) { var param = input as ASN1Integer; SecurityAssert.NotNull(param); X = param !.Value; var y = BigInteger.ModPow(parameters.G, X, parameters.P); DHPublicKey = new DHPublicKey(parameters, y); }
public static X509AlgorithmIdentifier FromObject(ASN1Object asn1) { var seq = asn1 as ASN1Sequence; SecurityAssert.NotNull(seq); SecurityAssert.Assert(seq !.Count >= 1); var algorithmOid = seq.Elements[0] as ASN1ObjectIdentifier; SecurityAssert.NotNull(algorithmOid); var parameters = seq.Elements.Skip(1).ToList(); return(new X509AlgorithmIdentifier(algorithmOid !, parameters)); }
public ExtendedKeyUsage( ArrayList usages) { ASN1EncodableVector v = new ASN1EncodableVector(); IEnumerator e = usages.GetEnumerator(); while (e.MoveNext()) { ASN1Object o = (ASN1Object)e.Current; v.add(o); this.usageTable.Add(o, o); } this.seq = new DERSequence(v); }
public SignedData( ASN1Sequence seq) { IEnumerator e = seq.getObjects(); e.MoveNext(); version = (DERInteger)e.Current; e.MoveNext(); digestAlgorithms = ((ASN1Set)e.Current); e.MoveNext(); contentInfo = ContentInfo.getInstance(e.Current); while (e.MoveNext()) { ASN1Object o = (ASN1Object)e.Current; // // an interesting feature of SignedData is that there appear // to be varying implementations... // for the moment we ignore anything which doesn't fit. // if (o is ASN1TaggedObject) { ASN1TaggedObject tagged = (ASN1TaggedObject)o; switch ((int)tagged.getTagNo()) { case 0: certBer = tagged is BERTaggedObject; certificates = ASN1Set.getInstance(tagged, false); break; case 1: crlsBer = tagged is BERTaggedObject; crls = ASN1Set.getInstance(tagged, false); break; default: throw new ArgumentException("unknown tag value " + tagged.getTagNo()); } } else { signerInfos = (ASN1Set)o; } } }
/** * creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. */ public Time( DateTime date) { // SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); // SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); // // dateF.setTimeZone(tz); // // string d = dateF.format(date) + "Z"; string d = date.ToString("yyyyMMddHHmmss") + "Z"; int year = Int32.Parse(d.Substring(0, 4)); if (year < 1950 || year > 2049) { time = new DERGeneralizedTime(d); } else { time = new DERUTCTime(d.Substring(2)); } }
private X509Name ReadName(ASN1Object asn1) { var result = new Dictionary <string, ASN1Object>(); var rdnSeq = ToSeq(asn1, 1); foreach (var rdn in rdnSeq.Elements) { var rdnSet = ToSet(rdn, 1); foreach (var attr in rdnSet.Elements) { var attrSeq = ToSeq(attr, 2, 2); var type = GetElement <ASN1ObjectIdentifier>(attrSeq, 0); var value = GetElement(attrSeq, 1); result.Add(type.Identifier, value); } } return(new X509Name(result)); }
public X962Parameters( ASN1Object obj) { this._params = obj; }
public void LoadASN1Structure(ASN1Object asn1Object) { _asnTree.LoadASN1Structure(asn1Object._object); }
public X962Parameters( X9ECParameters ecParameters) { this._params = ecParameters.toASN1Object(); }
/** * When the subjectAltName extension contains an Internet mail address, * the address MUST be included as an rfc822Name. The format of an * rfc822Name is an "addr-spec" as defined in RFC 822 [RFC 822]. * * When the subjectAltName extension contains a domain name service * label, the domain name MUST be stored in the dNSName (an IA5String). * The name MUST be in the "preferred name syntax," as specified by RFC * 1034 [RFC 1034]. * * When the subjectAltName extension contains a URI, the name MUST be * stored in the uniformResourceIdentifier (an IA5String). The name MUST * be a non-relative URL, and MUST follow the URL syntax and encoding * rules specified in [RFC 1738]. The name must include both a scheme * (e.g., "http" or "ftp") and a scheme-specific-part. The scheme- * specific-part must include a fully qualified domain name or IP * address as the host. * * When the subjectAltName extension contains a iPAddress, the address * MUST be stored in the octet string in "network byte order," as * specified in RFC 791 [RFC 791]. The least significant bit (LSB) of * each octet is the LSB of the corresponding byte in the network * address. For IP Version 4, as specified in RFC 791, the octet string * MUST contain exactly four octets. For IP Version 6, as specified in * RFC 1883, the octet string MUST contain exactly sixteen octets [RFC * 1883]. */ public GeneralName( ASN1Object name, int tag) { this.obj = name; this.tag = tag; }
public RecipientInfo( ASN1Object info) { this.info = info; }
public X9FieldID( ASN1Sequence seq) { this.id = (DERObjectIdentifier)seq.getObjectAt(0); this.parameters = (ASN1Object)seq.getObjectAt(1); }
public X509Extension(string id, bool critical, ASN1Object value) { Id = id; Critical = critical; Value = value; }
public OriginatorIdentifierOrKey( ASN1Object id) { this.id = id; }
/** * dump a DER object as a formatted string with indentation * * @param obj the ASN1Object to be dumped out. */ public static string _dumpAsString( string indent, ASN1Object obj) { if (obj is ASN1Sequence) { StringBuilder buf = new StringBuilder(); IEnumerator e = ((ASN1Sequence)obj).getObjects(); string tab = indent + TAB; buf.Append(indent); if (obj is DERSequence) { buf.Append("DER Sequence"); } else if (obj is BERSequence) { buf.Append("BER Sequence"); } else { buf.Append("Sequence"); } buf.Append(Environment.NewLine); while (e.MoveNext()) { object o = e.Current; if (o == null || o.Equals(new DERNull())) { buf.Append(tab); buf.Append("NULL"); buf.Append(Environment.NewLine); } else if (o is ASN1Object) { buf.Append(_dumpAsString(tab, (ASN1Object)o)); } else { buf.Append(_dumpAsString(tab, ((ASN1Encodable)o).toASN1Object())); } } return(buf.ToString()); } else if (obj is DERTaggedObject) { StringBuilder buf = new StringBuilder(); string tab = indent + TAB; buf.Append(indent); if (obj is BERTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DERTaggedObject o = (DERTaggedObject)obj; buf.Append(((int)o.getTagNo()).ToString()); buf.Append("]"); if (!o.isExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(Environment.NewLine); if (o.isEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(Environment.NewLine); } else { buf.Append(_dumpAsString(tab, o.getObject())); } return(buf.ToString()); } else if (obj is BERSet) { StringBuilder buf = new StringBuilder(); IEnumerator e = ((ASN1Set)obj).getObjects(); string tab = indent + TAB; buf.Append(indent); buf.Append("BER Set"); buf.Append(Environment.NewLine); while (e.MoveNext()) { object o = e.Current; if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(Environment.NewLine); } else if (o is ASN1Object) { buf.Append(_dumpAsString(tab, (ASN1Object)o)); } else { buf.Append(_dumpAsString(tab, ((ASN1Encodable)o).toASN1Object())); } } return(buf.ToString()); } else if (obj is DERSet) { StringBuilder buf = new StringBuilder(); IEnumerator e = ((ASN1Set)obj).getObjects(); string tab = indent + TAB; buf.Append(indent); buf.Append("DER Set"); buf.Append(Environment.NewLine); while (e.MoveNext()) { object o = e.Current; if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(Environment.NewLine); } else if (o is ASN1Object) { buf.Append(_dumpAsString(tab, (ASN1Object)o)); } else { buf.Append(_dumpAsString(tab, ((ASN1Encodable)o).toASN1Object())); } } return(buf.ToString()); } else if (obj is DERObjectIdentifier) { return(indent + "ObjectIdentifier(" + ((DERObjectIdentifier)obj).getId() + ")" + Environment.NewLine); } else if (obj is DERBoolean) { return(indent + "Boolean(" + ((DERBoolean)obj).isTrue() + ")" + Environment.NewLine); } else if (obj is DERInteger) { return(indent + "Integer(" + ((DERInteger)obj).getValue() + ")" + Environment.NewLine); } else if (obj is DEROctetString) { return(indent + obj.ToString() + "[" + ((ASN1OctetString)obj).getOctets().Length + "] " + Environment.NewLine); } else if (obj is DERIA5String) { return(indent + "IA5String(" + ((DERIA5String)obj).getString() + ") " + Environment.NewLine); } else if (obj is DERPrintableString) { return(indent + "PrintableString(" + ((DERPrintableString)obj).getString() + ") " + Environment.NewLine); } else if (obj is DERVisibleString) { return(indent + "VisibleString(" + ((DERVisibleString)obj).getString() + ") " + Environment.NewLine); } else if (obj is DERBMPString) { return(indent + "BMPString(" + ((DERBMPString)obj).getString() + ") " + Environment.NewLine); } else if (obj is DERT61String) { return(indent + "T61String(" + ((DERT61String)obj).getString() + ") " + Environment.NewLine); } else if (obj is DERUTCTime) { return(indent + "UTCTime(" + ((DERUTCTime)obj).getTime() + ") " + Environment.NewLine); } else if (obj is DERUnknownTag) { return(indent + "Unknown " + ((int)((DERUnknownTag)obj).getTag()).ToString("X") + " " + ByteArray2String(Hex.encode(((DERUnknownTag)obj).getData())) + Environment.NewLine); } else { return(indent + obj.ToString() + Environment.NewLine); } }
internal EncryptionScheme(ASN1Sequence seq) : base(seq) { objectId = (ASN1Object)seq.getObjectAt(0); obj = (ASN1Object)seq.getObjectAt(1); }
public ASN1ComponentTypeInfo(ASN1Type tip, ASN1Object defaultValue) { this.Type = tip; this.isOptional = false; this.DefaultValue = defaultValue; }
public void LoadASN1Structure(ASN1Object asn1Object) { _asnTree.LoadASN1Structure( asn1Object._object ); }
public SignerIdentifier( ASN1Object id) { this.id = id; }
public static ASN1ComponentTypeInfo Make(ASN1Type tip, bool optional, ASN1Object defaultValue) { return new ASN1ComponentTypeInfo(tip, optional, defaultValue); }