public KeyAgreeRecipientInformation(
            KeyAgreeRecipientInfo info,
            AlgorithmIdentifier encAlg,
            Stream data)
            : base(encAlg, AlgorithmIdentifier.GetInstance(info.KeyEncryptionAlgorithm), data)
        {
            _info = info;
//			_encAlg = encAlg;

            try
            {
                Asn1Sequence          s  = _info.RecipientEncryptedKeys;
                RecipientEncryptedKey id = RecipientEncryptedKey.GetInstance(s[0]);

                Asn1.Cms.IssuerAndSerialNumber iAnds = id.Identifier.IssuerAndSerialNumber;

//				byte[] issuerBytes = iAnds.Name.GetEncoded();

                _rid = new RecipientID();
//				_rid.SetIssuer(issuerBytes);
                _rid.Issuer       = iAnds.Name;
                _rid.SerialNumber = iAnds.SerialNumber.Value;

                _encryptedKey = id.EncryptedKey;
            }
            catch (IOException e)
            {
                throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", e);
            }
        }
 internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info, CmsSecureReadable secureReadable)
 {
     try
     {
         foreach (Asn1Encodable asn1Encodable in info.RecipientEncryptedKeys)
         {
             RecipientEncryptedKey       instance    = RecipientEncryptedKey.GetInstance(asn1Encodable.ToAsn1Object());
             RecipientID                 recipientID = new RecipientID();
             KeyAgreeRecipientIdentifier identifier  = instance.Identifier;
             Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber issuerAndSerialNumber = identifier.IssuerAndSerialNumber;
             if (issuerAndSerialNumber != null)
             {
                 recipientID.Issuer       = issuerAndSerialNumber.Name;
                 recipientID.SerialNumber = issuerAndSerialNumber.SerialNumber.Value;
             }
             else
             {
                 RecipientKeyIdentifier rKeyID = identifier.RKeyID;
                 recipientID.SubjectKeyIdentifier = rKeyID.SubjectKeyIdentifier.GetOctets();
             }
             infos.Add(new KeyAgreeRecipientInformation(info, recipientID, instance.EncryptedKey, secureReadable));
         }
     }
     catch (IOException innerException)
     {
         throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", innerException);
     }
 }
Esempio n. 3
0
 internal static void ReadRecipientInfo(global::System.Collections.IList infos, KeyAgreeRecipientInfo info, CmsSecureReadable secureReadable)
 {
     //IL_00bb: Expected O, but got Unknown
     //IL_00c2: Unknown result type (might be due to invalid IL or missing references)
     try
     {
         global::System.Collections.IEnumerator enumerator = info.RecipientEncryptedKeys.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 Asn1Encodable               asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                 RecipientEncryptedKey       instance      = RecipientEncryptedKey.GetInstance(asn1Encodable.ToAsn1Object());
                 RecipientID                 recipientID   = new RecipientID();
                 KeyAgreeRecipientIdentifier identifier    = instance.Identifier;
                 Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber issuerAndSerialNumber = identifier.IssuerAndSerialNumber;
                 if (issuerAndSerialNumber != null)
                 {
                     recipientID.Issuer       = issuerAndSerialNumber.Name;
                     recipientID.SerialNumber = issuerAndSerialNumber.SerialNumber.Value;
                 }
                 else
                 {
                     RecipientKeyIdentifier rKeyID = identifier.RKeyID;
                     recipientID.SubjectKeyIdentifier = rKeyID.SubjectKeyIdentifier.GetOctets();
                 }
                 infos.Add((object)new KeyAgreeRecipientInformation(info, recipientID, instance.EncryptedKey, secureReadable));
             }
         }
         finally
         {
             global::System.IDisposable disposable = enumerator as global::System.IDisposable;
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         }
     }
     catch (IOException val)
     {
         IOException val2 = val;
         throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", (global::System.Exception)(object) val2);
     }
 }
        internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info,
                                               AlgorithmIdentifier encAlg, AlgorithmIdentifier macAlg, AlgorithmIdentifier authEncAlg,
                                               Stream data)
        {
            try
            {
                foreach (Asn1Encodable rek in info.RecipientEncryptedKeys)
                {
                    RecipientEncryptedKey id = RecipientEncryptedKey.GetInstance(rek.ToAsn1Object());

                    RecipientID rid = new RecipientID();

                    Asn1.Cms.KeyAgreeRecipientIdentifier karid = id.Identifier;

                    Asn1.Cms.IssuerAndSerialNumber iAndSN = karid.IssuerAndSerialNumber;
                    if (iAndSN != null)
                    {
                        rid.Issuer       = iAndSN.Name;
                        rid.SerialNumber = iAndSN.SerialNumber.Value;
                    }
                    else
                    {
                        Asn1.Cms.RecipientKeyIdentifier rKeyID = karid.RKeyID;

                        // Note: 'date' and 'other' fields of RecipientKeyIdentifier appear to be only informational

                        rid.SubjectKeyIdentifier = rKeyID.SubjectKeyIdentifier.GetOctets();
                    }

                    infos.Add(new KeyAgreeRecipientInformation(info, rid, id.EncryptedKey,
                                                               encAlg, macAlg, authEncAlg, data));
                }
            }
            catch (IOException e)
            {
                throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", e);
            }
        }