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; }
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]); } } }