Пример #1
0
        internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out RecipientInfoAsn decoded)
        {
            decoded = default;
            Asn1Tag tag = reader.PeekTag();

            if (tag.HasSameClassAndValue(Asn1Tag.Sequence))
            {
                KeyTransRecipientInfoAsn tmpKtri;
                KeyTransRecipientInfoAsn.Decode(ref reader, rebind, out tmpKtri);
                decoded.Ktri = tmpKtri;
            }
            else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1)))
            {
                KeyAgreeRecipientInfoAsn tmpKari;
                KeyAgreeRecipientInfoAsn.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 1), rebind, out tmpKari);
                decoded.Kari = tmpKari;
            }
            else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2)))
            {
                KEKRecipientInfoAsn kekRecipientInfo;
                KEKRecipientInfoAsn.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 2), rebind, out kekRecipientInfo);
                decoded.KrecipientInfo = kekRecipientInfo;
            }
            else
            {
                throw new CryptographicException();
            }
        }
Пример #2
0
        internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory <byte> rebind, out KEKRecipientInfoAsn decoded)
        {
            decoded = default;
            KEKIdentifierAsn       kekIdentifier;
            AlgorithmIdentifierAsn algIdentifier;
            AsnValueReader         sequenceReader = reader.ReadSequence(expectedTag);
            int version;

            if (sequenceReader.TryReadInt32(out version))
            {
                decoded.Version = version;
            }


            KEKIdentifierAsn.Decode(ref sequenceReader, Asn1Tag.Sequence, rebind, out kekIdentifier);
            AlgorithmIdentifierAsn.Decode(ref sequenceReader, Asn1Tag.Sequence, rebind, out algIdentifier);
            var encryptedKey = sequenceReader.ReadOctetString();

            decoded.KEKId            = kekIdentifier;
            decoded.KeyEncryptionAlg = algIdentifier;
            decoded.EncryptedKey     = encryptedKey;
        }