コード例 #1
0
 /// <summary>
 /// Cryptographically unprotects a piece of protected data.
 /// </summary>
 /// <param name="protector">The protector to use.</param>
 /// <param name="protectedData">The protected data to unprotect.</param>
 /// <param name="expiration">An 'out' parameter which upon a successful unprotect
 /// operation receives the expiration date of the payload.</param>
 /// <returns>The plaintext form of the protected data.</returns>
 /// <exception cref="CryptographicException">
 /// Thrown if <paramref name="protectedData"/> is invalid, malformed, or expired.
 /// </exception>
 public static string Unprotect([NotNull] this ITimeLimitedDataProtector protector, [NotNull] string protectedData, out DateTimeOffset expiration)
 {
     var wrappingProtector = new TimeLimitedWrappingProtector(protector);
     string retVal = wrappingProtector.Unprotect(protectedData);
     expiration = wrappingProtector.Expiration;
     return retVal;
 }
コード例 #2
0
        /// <summary>
        /// Cryptographically protects a piece of plaintext data, expiring the data at
        /// the chosen time.
        /// </summary>
        /// <param name="protector">The protector to use.</param>
        /// <param name="plaintext">The plaintext data to protect.</param>
        /// <param name="expiration">The time when this payload should expire.</param>
        /// <returns>The protected form of the plaintext data.</returns>
        public static string Protect(this ITimeLimitedDataProtector protector, string plaintext, DateTimeOffset expiration)
        {
            if (protector == null)
            {
                throw new ArgumentNullException(nameof(protector));
            }

            if (plaintext == null)
            {
                throw new ArgumentNullException(nameof(plaintext));
            }

            var wrappingProtector = new TimeLimitedWrappingProtector(protector) { Expiration = expiration };
            return wrappingProtector.Protect(plaintext);
        }
コード例 #3
0
        /// <summary>
        /// Cryptographically unprotects a piece of protected data.
        /// </summary>
        /// <param name="protector">The protector to use.</param>
        /// <param name="protectedData">The protected data to unprotect.</param>
        /// <param name="expiration">An 'out' parameter which upon a successful unprotect
        /// operation receives the expiration date of the payload.</param>
        /// <returns>The plaintext form of the protected data.</returns>
        /// <exception cref="System.Security.Cryptography.CryptographicException">
        /// Thrown if <paramref name="protectedData"/> is invalid, malformed, or expired.
        /// </exception>
        public static string Unprotect(this ITimeLimitedDataProtector protector, string protectedData, out DateTimeOffset expiration)
        {
            if (protector == null)
            {
                throw new ArgumentNullException(nameof(protector));
            }

            if (protectedData == null)
            {
                throw new ArgumentNullException(nameof(protectedData));
            }

            var    wrappingProtector = new TimeLimitedWrappingProtector(protector);
            string retVal            = wrappingProtector.Unprotect(protectedData);

            expiration = wrappingProtector.Expiration;
            return(retVal);
        }
コード例 #4
0
        /// <summary>
        /// Cryptographically protects a piece of plaintext data, expiring the data at
        /// the chosen time.
        /// </summary>
        /// <param name="protector">The protector to use.</param>
        /// <param name="plaintext">The plaintext data to protect.</param>
        /// <param name="expiration">The time when this payload should expire.</param>
        /// <returns>The protected form of the plaintext data.</returns>
        public static string Protect(this ITimeLimitedDataProtector protector, string plaintext, DateTimeOffset expiration)
        {
            if (protector == null)
            {
                throw new ArgumentNullException(nameof(protector));
            }

            if (plaintext == null)
            {
                throw new ArgumentNullException(nameof(plaintext));
            }

            var wrappingProtector = new TimeLimitedWrappingProtector(protector)
            {
                Expiration = expiration
            };

            return(wrappingProtector.Protect(plaintext));
        }
コード例 #5
0
        /// <summary>
        /// Cryptographically unprotects a piece of protected data.
        /// </summary>
        /// <param name="protector">The protector to use.</param>
        /// <param name="protectedData">The protected data to unprotect.</param>
        /// <param name="expiration">An 'out' parameter which upon a successful unprotect
        /// operation receives the expiration date of the payload.</param>
        /// <returns>The plaintext form of the protected data.</returns>
        /// <exception cref="CryptographicException">
        /// Thrown if <paramref name="protectedData"/> is invalid, malformed, or expired.
        /// </exception>
        public static string Unprotect(this ITimeLimitedDataProtector protector, string protectedData, out DateTimeOffset expiration)
        {
            if (protector == null)
            {
                throw new ArgumentNullException(nameof(protector));
            }

            if (protectedData == null)
            {
                throw new ArgumentNullException(nameof(protectedData));
            }

            var wrappingProtector = new TimeLimitedWrappingProtector(protector);
            string retVal = wrappingProtector.Unprotect(protectedData);
            expiration = wrappingProtector.Expiration;
            return retVal;
        }
コード例 #6
0
 /// <summary>
 /// Cryptographically protects a piece of plaintext data, expiring the data at
 /// the chosen time.
 /// </summary>
 /// <param name="protector">The protector to use.</param>
 /// <param name="plaintext">The plaintext data to protect.</param>
 /// <param name="expiration">The time when this payload should expire.</param>
 /// <returns>The protected form of the plaintext data.</returns>
 public static string Protect([NotNull] this ITimeLimitedDataProtector protector, [NotNull] string plaintext, DateTimeOffset expiration)
 {
     var wrappingProtector = new TimeLimitedWrappingProtector(protector) { Expiration = expiration };
     return wrappingProtector.Protect(plaintext);
 }