public RecipientInfo(ASN1 data) { if (data.Tag != 48) { throw new ArgumentException("Invalid RecipientInfo"); } ASN1 aSN = data[0]; if (aSN.Tag != 2) { throw new ArgumentException("missing Version"); } _version = aSN.Value[0]; ASN1 aSN2 = data[1]; if (aSN2.Tag == 128 && _version == 3) { _ski = aSN2.Value; } else { _issuer = X501.ToString(aSN2[0]); _serial = aSN2[1].Value; } ASN1 aSN3 = data[2]; _oid = ASN1Convert.ToOid(aSN3[0]); ASN1 aSN4 = data[3]; _key = aSN4.Value; }
public RecipientInfo(ASN1 data) { if (data.Tag != 48) { throw new ArgumentException("Invalid RecipientInfo"); } ASN1 asn = data[0]; if (asn.Tag != 2) { throw new ArgumentException("missing Version"); } this._version = (int)asn.Value[0]; ASN1 asn2 = data[1]; if (asn2.Tag == 128 && this._version == 3) { this._ski = asn2.Value; } else { this._issuer = X501.ToString(asn2[0]); this._serial = asn2[1].Value; } ASN1 asn3 = data[2]; this._oid = ASN1Convert.ToOid(asn3[0]); ASN1 asn4 = data[3]; this._key = asn4.Value; }
public EnvelopedData(ASN1 asn1) : this() { if ((asn1[0].Tag != 0x30) || (asn1[0].Count < 3)) { throw new ArgumentException("Invalid EnvelopedData"); } if (asn1[0][0].Tag != 0x02) { throw new ArgumentException("Invalid version"); } _version = asn1[0][0].Value[0]; // recipientInfos ASN1 recipientInfos = asn1 [0][1]; if (recipientInfos.Tag != 0x31) { throw new ArgumentException("missing RecipientInfos"); } for (int i = 0; i < recipientInfos.Count; i++) { ASN1 recipientInfo = recipientInfos [i]; _recipientInfos.Add(new RecipientInfo(recipientInfo)); } ASN1 encryptedContentInfo = asn1[0][2]; if (encryptedContentInfo.Tag != 0x30) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 contentType = encryptedContentInfo [0]; if (contentType.Tag != 0x06) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } _content = new ContentInfo(ASN1Convert.ToOid(contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } _encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; ASN1 encryptedContent = encryptedContentInfo [2]; if (encryptedContent.Tag != 0x80) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } _encrypted = encryptedContent.Value; }
static public ASN1 AlgorithmIdentifier(string oid, ASN1 parameters) { ASN1 ai = new ASN1(0x30); ai.Add(ASN1Convert.FromOid(oid)); ai.Add(parameters); return(ai); }
public static ASN1 AlgorithmIdentifier(string oid) { ASN1 asn = new ASN1(48); asn.Add(ASN1Convert.FromOid(oid)); asn.Add(new ASN1(5)); return(asn); }
public static ASN1 AlgorithmIdentifier(string oid, ASN1 parameters) { ASN1 aSN = new ASN1(48); aSN.Add(ASN1Convert.FromOid(oid)); aSN.Add(parameters); return(aSN); }
public static ASN1 Attribute(string oid, ASN1 value) { ASN1 asn = new ASN1(0x30); asn.Add(ASN1Convert.FromOid(oid)); asn.Add(new ASN1(0x31)).Add(value); return(asn); }
static public ASN1 AlgorithmIdentifier(string oid) { ASN1 ai = new ASN1(0x30); ai.Add(ASN1Convert.FromOid(oid)); ai.Add(new ASN1(0x05)); // NULL return(ai); }
public static ASN1 Attribute(string oid, ASN1 value) { ASN1 asn = new ASN1(48); asn.Add(ASN1Convert.FromOid(oid)); ASN1 asn2 = asn.Add(new ASN1(49)); asn2.Add(value); return(asn); }
public static ASN1 Attribute(string oid, ASN1 value) { ASN1 aSN = new ASN1(48); aSN.Add(ASN1Convert.FromOid(oid)); ASN1 aSN2 = aSN.Add(new ASN1(49)); aSN2.Add(value); return(aSN); }
static public ASN1 Attribute(string oid, ASN1 value) { ASN1 attr = new ASN1(0x30); attr.Add(ASN1Convert.FromOid(oid)); ASN1 aset = attr.Add(new ASN1(0x31)); aset.Add(value); return(attr); }
internal Mono.Security.ASN1 GetASN1() { Mono.Security.ASN1 asn = new Mono.Security.ASN1(0x30); asn.Add(ASN1Convert.FromOid(this.contentType)); if ((this.content != null) && (this.content.Count > 0)) { asn.Add(this.content); } return(asn); }
internal ASN1 GetASN1() { ASN1 aSN = new ASN1(48); aSN.Add(ASN1Convert.FromOid(contentType)); if (content != null && content.Count > 0) { aSN.Add(content); } return(aSN); }
public SignerInfo(ASN1 asn1) : this() { if (asn1[0].Tag != 48 || asn1[0].Count < 5) { throw new ArgumentException("Invalid SignedData"); } if (asn1[0][0].Tag != 2) { throw new ArgumentException("Invalid version"); } version = asn1[0][0].Value[0]; ASN1 aSN = asn1[0][1]; if (aSN.Tag == 128 && version == 3) { ski = aSN.Value; } else { issuer = X501.ToString(aSN[0]); serial = aSN[1].Value; } ASN1 aSN2 = asn1[0][2]; hashAlgorithm = ASN1Convert.ToOid(aSN2[0]); int num = 3; ASN1 aSN3 = asn1[0][num]; if (aSN3.Tag == 160) { num++; for (int i = 0; i < aSN3.Count; i++) { authenticatedAttributes.Add(aSN3[i]); } } num++; ASN1 aSN4 = asn1[0][num++]; if (aSN4.Tag == 4) { signature = aSN4.Value; } ASN1 aSN5 = asn1[0][num]; if (aSN5 != null && aSN5.Tag == 161) { for (int j = 0; j < aSN5.Count; j++) { unauthenticatedAttributes.Add(aSN5[j]); } } }
internal ASN1 GetASN1() { ASN1 asn = new ASN1(48); asn.Add(ASN1Convert.FromOid(this.contentType)); if (this.content != null && this.content.Count > 0) { asn.Add(this.content); } return(asn); }
public SignerInfo(ASN1 asn1) : this() { if (asn1[0].Tag != 48 || asn1[0].Count < 5) { throw new ArgumentException("Invalid SignedData"); } if (asn1[0][0].Tag != 2) { throw new ArgumentException("Invalid version"); } this.version = asn1[0][0].Value[0]; ASN1 asn2 = asn1[0][1]; if (asn2.Tag == 128 && this.version == 3) { this.ski = asn2.Value; } else { this.issuer = X501.ToString(asn2[0]); this.serial = asn2[1].Value; } ASN1 asn3 = asn1[0][2]; this.hashAlgorithm = ASN1Convert.ToOid(asn3[0]); int num = 3; ASN1 asn4 = asn1[0][num]; if (asn4.Tag == 160) { num++; for (int i = 0; i < asn4.Count; i++) { this.authenticatedAttributes.Add(asn4[i]); } } num++; ASN1 asn5 = asn1[0][num++]; if (asn5.Tag == 4) { this.signature = asn5.Value; } ASN1 asn6 = asn1[0][num]; if (asn6 != null && asn6.Tag == 161) { for (int j = 0; j < asn6.Count; j++) { this.unauthenticatedAttributes.Add(asn6[j]); } } }
public EnvelopedData(ASN1 asn1) : this() { if (asn1[0].Tag != 48 || asn1[0].Count < 3) { throw new ArgumentException("Invalid EnvelopedData"); } if (asn1[0][0].Tag != 2) { throw new ArgumentException("Invalid version"); } _version = asn1[0][0].Value[0]; ASN1 aSN = asn1[0][1]; if (aSN.Tag != 49) { throw new ArgumentException("missing RecipientInfos"); } for (int i = 0; i < aSN.Count; i++) { ASN1 data = aSN[i]; _recipientInfos.Add(new RecipientInfo(data)); } ASN1 aSN2 = asn1[0][2]; if (aSN2.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 aSN3 = aSN2[0]; if (aSN3.Tag != 6) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } _content = new ContentInfo(ASN1Convert.ToOid(aSN3)); ASN1 aSN4 = aSN2[1]; if (aSN4.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } _encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(aSN4[0])); _encryptionAlgorithm.Content = aSN4[1]; ASN1 aSN5 = aSN2[2]; if (aSN5.Tag != 128) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } _encrypted = aSN5.Value; }
public EnvelopedData(ASN1 asn1) : this() { if (asn1[0].Tag != 48 || asn1[0].Count < 3) { throw new ArgumentException("Invalid EnvelopedData"); } if (asn1[0][0].Tag != 2) { throw new ArgumentException("Invalid version"); } this._version = asn1[0][0].Value[0]; ASN1 asn2 = asn1[0][1]; if (asn2.Tag != 49) { throw new ArgumentException("missing RecipientInfos"); } for (int i = 0; i < asn2.Count; i++) { ASN1 data = asn2[i]; this._recipientInfos.Add(new PKCS7.RecipientInfo(data)); } ASN1 asn3 = asn1[0][2]; if (asn3.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 asn4 = asn3[0]; if (asn4.Tag != 6) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn4)); ASN1 asn5 = asn3[1]; if (asn5.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } this._encryptionAlgorithm = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn5[0])); this._encryptionAlgorithm.Content = asn5[1]; ASN1 asn6 = asn3[2]; if (asn6.Tag != 128) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } this._encrypted = asn6.Value; }
internal ASN1 GetASN1() { // ContentInfo ::= SEQUENCE { ASN1 contentInfo = new ASN1(0x30); // contentType ContentType, -> ContentType ::= OBJECT IDENTIFIER contentInfo.Add(ASN1Convert.FromOid(contentType)); // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL if ((content != null) && (content.Count > 0)) { contentInfo.Add(content); } return(contentInfo); }
public EncryptedData(ASN1 asn1) : this() { if ((asn1.Tag != 0x30) || (asn1.Count < 2)) { throw new ArgumentException("Invalid EncryptedData"); } if (asn1 [0].Tag != 0x02) { throw new ArgumentException("Invalid version"); } _version = asn1 [0].Value [0]; ASN1 encryptedContentInfo = asn1 [1]; if (encryptedContentInfo.Tag != 0x30) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 contentType = encryptedContentInfo [0]; if (contentType.Tag != 0x06) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } _content = new ContentInfo(ASN1Convert.ToOid(contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } _encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; ASN1 encryptedContent = encryptedContentInfo [2]; if (encryptedContent.Tag != 0x80) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } _encrypted = encryptedContent.Value; }
public ContentInfo(ASN1 asn1) { if (asn1.Tag != 48 || (asn1.Count < 1 && asn1.Count > 2)) { throw new ArgumentException("Invalid ASN1"); } if (asn1[0].Tag != 6) { throw new ArgumentException("Invalid contentType"); } contentType = ASN1Convert.ToOid(asn1[0]); if (asn1.Count > 1) { if (asn1[1].Tag != 160) { throw new ArgumentException("Invalid content"); } content = asn1[1]; } }
public ContentInfo(Mono.Security.ASN1 asn1) { if ((asn1.Tag != 0x30) || ((asn1.Count < 1) && (asn1.Count > 2))) { throw new ArgumentException("Invalid ASN1"); } if (asn1[0].Tag != 6) { throw new ArgumentException("Invalid contentType"); } this.contentType = ASN1Convert.ToOid(asn1[0]); if (asn1.Count > 1) { if (asn1[1].Tag != 160) { throw new ArgumentException("Invalid content"); } this.content = asn1[1]; } }
public EncryptedData(ASN1 asn1) : this() { if (asn1.Tag != 48 || asn1.Count < 2) { throw new ArgumentException("Invalid EncryptedData"); } if (asn1[0].Tag != 2) { throw new ArgumentException("Invalid version"); } _version = asn1[0].Value[0]; ASN1 aSN = asn1[1]; if (aSN.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 aSN2 = aSN[0]; if (aSN2.Tag != 6) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } _content = new ContentInfo(ASN1Convert.ToOid(aSN2)); ASN1 aSN3 = aSN[1]; if (aSN3.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } _encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(aSN3[0])); _encryptionAlgorithm.Content = aSN3[1]; ASN1 aSN4 = aSN[2]; if (aSN4.Tag != 128) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } _encrypted = aSN4.Value; }
public ContentInfo(ASN1 asn1) { // SEQUENCE with 1 or 2 elements if ((asn1.Tag != 0x30) || ((asn1.Count < 1) && (asn1.Count > 2))) { throw new ArgumentException("Invalid ASN1"); } if (asn1[0].Tag != 0x06) { throw new ArgumentException("Invalid contentType"); } contentType = ASN1Convert.ToOid(asn1[0]); if (asn1.Count > 1) { if (asn1[1].Tag != 0xA0) { throw new ArgumentException("Invalid content"); } content = asn1[1]; } }
public EncryptedData(ASN1 asn1) : this() { if (asn1.Tag != 48 || asn1.Count < 2) { throw new ArgumentException("Invalid EncryptedData"); } if (asn1[0].Tag != 2) { throw new ArgumentException("Invalid version"); } this._version = asn1[0].Value[0]; ASN1 asn2 = asn1[1]; if (asn2.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo"); } ASN1 asn3 = asn2[0]; if (asn3.Tag != 6) { throw new ArgumentException("missing EncryptedContentInfo.ContentType"); } this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn3)); ASN1 asn4 = asn2[1]; if (asn4.Tag != 48) { throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); } this._encryptionAlgorithm = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn4[0])); this._encryptionAlgorithm.Content = asn4[1]; ASN1 asn5 = asn2[2]; if (asn5.Tag != 128) { throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent"); } this._encrypted = asn5.Value; }
public RecipientInfo(ASN1 data) { if (data.Tag != 0x30) { throw new ArgumentException("Invalid RecipientInfo"); } ASN1 version = data [0]; if (version.Tag != 0x02) { throw new ArgumentException("missing Version"); } _version = version.Value [0]; // issuerAndSerialNumber IssuerAndSerialNumber ASN1 subjectIdentifierType = data [1]; if ((subjectIdentifierType.Tag == 0x80) && (_version == 3)) { _ski = subjectIdentifierType.Value; } else { _issuer = X501.ToString(subjectIdentifierType [0]); _serial = subjectIdentifierType [1].Value; } ASN1 keyEncryptionAlgorithm = data [2]; _oid = ASN1Convert.ToOid(keyEncryptionAlgorithm [0]); ASN1 encryptedKey = data [3]; _key = encryptedKey.Value; }
// TODO: INCOMPLETE public SignerInfo(ASN1 asn1) : this() { if ((asn1[0].Tag != 0x30) || (asn1[0].Count < 5)) { throw new ArgumentException("Invalid SignedData"); } // version Version if (asn1[0][0].Tag != 0x02) { throw new ArgumentException("Invalid version"); } version = asn1[0][0].Value[0]; // issuerAndSerialNumber IssuerAndSerialNumber ASN1 subjectIdentifierType = asn1 [0][1]; if ((subjectIdentifierType.Tag == 0x80) && (version == 3)) { ski = subjectIdentifierType.Value; } else { issuer = X501.ToString(subjectIdentifierType [0]); serial = subjectIdentifierType [1].Value; } // digestAlgorithm DigestAlgorithmIdentifier ASN1 digestAlgorithm = asn1 [0][2]; hashAlgorithm = ASN1Convert.ToOid(digestAlgorithm [0]); // authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL int n = 3; ASN1 authAttributes = asn1 [0][n]; if (authAttributes.Tag == 0xA0) { n++; for (int i = 0; i < authAttributes.Count; i++) { authenticatedAttributes.Add(authAttributes [i]); } } // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier n++; // ASN1 digestEncryptionAlgorithm = asn1 [0][n++]; // string digestEncryptionAlgorithmOid = ASN1Convert.ToOid (digestEncryptionAlgorithm [0]); // encryptedDigest EncryptedDigest ASN1 encryptedDigest = asn1 [0][n++]; if (encryptedDigest.Tag == 0x04) { signature = encryptedDigest.Value; } // unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL ASN1 unauthAttributes = asn1 [0][n]; if ((unauthAttributes != null) && (unauthAttributes.Tag == 0xA1)) { for (int i = 0; i < unauthAttributes.Count; i++) { unauthenticatedAttributes.Add(unauthAttributes [i]); } } }