Table of Contents

Class UriExtensions

Namespace
Cuemon.Extensions.Net.Security
Assembly
Cuemon.Extensions.Net.dll

Extension methods for the Uri class.

public static class UriExtensions
Inheritance
UriExtensions

Examples

The following example demonstrates how to sign and validate a with .

using System;
using System.Text;
using Cuemon.Extensions.Net.Security;

namespace MyApp.Examples
{
    public static class SignedUriExtensionsExample
    {
        public static void Demonstrate()
        {
            var secret = Encoding.UTF8.GetBytes("1234");
            var location = new Uri("https://example.com/search?q=cuemon");
            var signed = location.ToSignedUri(secret, DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow.AddMinutes(1));

            signed.ValidateSignedUri(secret);

            Console.WriteLine(signed != location);
            Console.WriteLine(signed.AbsoluteUri);
        }
    }
}

Methods

ToSignedUri(Uri, byte[], DateTime?, DateTime?, Action<SignedUriOptions>)

Converts the specified uri to a signed and tampering protected Uri.

public static Uri ToSignedUri(this Uri uri, byte[] secret, DateTime? signedStart = null, DateTime? signedExpiry = null, Action<SignedUriOptions> setup = null)

Parameters

uri Uri

The URI to protect from tampering.

secret byte[]

The secret key for the encryption.

signedStart DateTime?

The time, expressed as the Coordinated Universal Time (UTC), at which the signed URI becomes valid.

signedExpiry DateTime?

The time, expressed as the Coordinated Universal Time (UTC), at which the signed URI becomes invalid.

setup Action<SignedUriOptions>

The SignedUriOptions which may be configured.

Returns

Uri

A Uri that is equivalent to uri but signed and protected from tampering.

ValidateSignedUri(Uri, byte[], Action<SignedUriOptions>)

Reads and validates the specified signedUri.

public static void ValidateSignedUri(this Uri signedUri, byte[] secret, Action<SignedUriOptions> setup = null)

Parameters

signedUri Uri

The signed URI that needs to be validated.

secret byte[]

The secret key for the encryption.

setup Action<SignedUriOptions>

The SignedUriOptions which may be configured.

Exceptions

SecurityException

signedUri did not have a signature specified - or - signedUri has an invalid signature.

See Also