Пример #1
0
        /// <summary>
        /// Re-instantiates an <see cref="Association"/> previously persisted in a database or some
        /// other shared store.
        /// </summary>
        /// <param name="handle">
        /// The <see cref="Handle"/> property of the previous <see cref="Association"/> instance.
        /// </param>
        /// <param name="expires">
        /// The value of the <see cref="Expires"/> property of the previous <see cref="Association"/> instance.
        /// </param>
        /// <param name="privateData">
        /// The byte array returned by a call to <see cref="SerializePrivateData"/> on the previous
        /// <see cref="Association"/> instance.
        /// </param>
        /// <returns>
        /// The newly dehydrated <see cref="Association"/>, which can be returned
        /// from a custom association store's
        /// <see cref="IAssociationStore&lt;TKey&gt;.GetAssociation(TKey)"/> method.
        /// </returns>
        public static Association Deserialize(string handle, DateTime expires, byte[] privateData)
        {
            if (string.IsNullOrEmpty(handle))
            {
                throw new ArgumentNullException("handle");
            }
            if (privateData == null)
            {
                throw new ArgumentNullException("privateData");
            }
            expires = expires.ToUniversalTime();
            TimeSpan remainingLifeLength = expires - DateTime.UtcNow;

            byte[] secret = privateData;             // the whole of privateData is the secret key for now.
            // We figure out what derived type to instantiate based on the length of the secret.
            try {
                return(HmacShaAssociation.Create(secret.Length, handle, secret, remainingLifeLength));
            } catch (ArgumentException ex) {
                throw new ArgumentException(Strings.BadAssociationPrivateData, "privateData", ex);
            }
        }
Пример #2
0
        internal bool IsAssociationInPermittedRange(Protocol protocol, string associationType)
        {
            int lengthInBits = HmacShaAssociation.GetSecretLength(protocol, associationType) * 8;

            return(lengthInBits >= MinimumHashBitLength && lengthInBits <= MaximumHashBitLength);
        }