void decode(Byte[] rawData) { var asn = new Asn1Reader(rawData); asn.MoveNext(); Version = (Int32)Asn1Utils.DecodeInteger(asn.GetTagRawData()); asn.MoveNextCurrentLevel(); Issuer = new PkcsSubjectIdentifier(asn.GetTagRawData()); asn.MoveNextCurrentLevel(); HashAlgorithm = new AlgorithmIdentifier(asn.GetTagRawData()); asn.MoveNextCurrentLevel(); if (asn.Tag == 0xa0) { _authAttributes.Decode(asn.GetTagRawData()); asn.MoveNextCurrentLevel(); } EncryptedHashAlgorithm = new AlgorithmIdentifier(asn.GetTagRawData()); asn.MoveNextCurrentLevel(); EncryptedHash = asn.GetPayload(); if (asn.MoveNextCurrentLevel() && asn.Tag == 0xa1) { _unauthAttributes.Decode(asn.GetTagRawData()); } _rawData.AddRange(rawData); }
void signContent(MessageSigner messageSigner, Byte[] content) { hashAlgId = new AlgorithmIdentifier(messageSigner.HashingAlgorithm.ToOid(), new Byte[0]); pubKeyAlgId = new AlgorithmIdentifier(messageSigner.PublicKeyAlgorithm, new Byte[0]); prepareSigning(content); SignedContentBlob signedBlob; if (_authAttributes.Any()) { // auth attributes are encoded as IMPLICIT (OPTIONAL), but RFC2315 ยง9.3 requires signature computation for SET var attrBytes = _authAttributes.Encode(); attrBytes[0] = 0x31; signedBlob = new SignedContentBlob(attrBytes, ContentBlobType.ToBeSignedBlob); } else { if (content == null) { throw new ArgumentException("'content' parameter cannot be null if no authenticated attributes present."); } signedBlob = new SignedContentBlob(content, ContentBlobType.ToBeSignedBlob); } signerCert = new PkcsSubjectIdentifier(messageSigner.SignerCertificate, SubjectIdentifier); signedBlob.Sign(messageSigner); hashValue = signedBlob.Signature.Value; }
void initializeFromSignerInfo(PkcsSignerInfo signerInfo) { Version = signerInfo.Version; SubjectIdentifier = signerInfo.Issuer.Type; signerCert = signerInfo.Issuer; X509Attribute attribute = signerInfo.AuthenticatedAttributes.FirstOrDefault(x => x.Oid.Value == CONTENT_TYPE); if (attribute != null) { ContentType = new Asn1ObjectIdentifier(attribute.RawData).Value; } pubKeyAlgId = signerInfo.EncryptedHashAlgorithm; hashAlgId = signerInfo.HashAlgorithm; hashValue = signerInfo.EncryptedHash; _authAttributes.AddRange(signerInfo.AuthenticatedAttributes); }