예제 #1
0
        internal KeyTransRecipientInformation(
            KeyTransRecipientInfo info,
            CmsSecureReadable secureReadable)
            : base(info.KeyEncryptionAlgorithm, secureReadable)
        {
            this.info = info;
            this.rid  = new RecipientID();

            RecipientIdentifier r = info.RecipientIdentifier;

            try
            {
                if (r.IsTagged)
                {
                    Asn1OctetString octs = Asn1OctetString.GetInstance(r.ID);

                    rid.SubjectKeyIdentifier = octs.GetOctets();
                }
                else
                {
                    IssuerAndSerialNumber iAnds = IssuerAndSerialNumber.GetInstance(r.ID);

                    rid.Issuer       = iAnds.Name;
                    rid.SerialNumber = iAnds.SerialNumber.Value;
                }
            }
            catch (IOException)
            {
                throw new ArgumentException("invalid rid in KeyTransRecipientInformation");
            }
        }
        /**
         * return an KeyAgreeRecipientIdentifier object from the given object.
         *
         * @param obj the object we want converted.
         * @exception ArgumentException if the object cannot be converted.
         */
        public static KeyAgreeRecipientIdentifier GetInstance(
            object obj)
        {
            if (obj == null || obj is KeyAgreeRecipientIdentifier)
            {
                return((KeyAgreeRecipientIdentifier)obj);
            }

            if (obj is Asn1Sequence)
            {
                return(new KeyAgreeRecipientIdentifier(IssuerAndSerialNumber.GetInstance(obj)));
            }

            if (obj is Asn1TaggedObject && ((Asn1TaggedObject)obj).TagNo == 0)
            {
                return(new KeyAgreeRecipientIdentifier(RecipientKeyIdentifier.GetInstance(
                                                           (Asn1TaggedObject)obj, false)));
            }

            throw new ArgumentException("Invalid KeyAgreeRecipientIdentifier: " + obj.GetType().FullName, "obj");
        }