BuildPolicyForSignedUrl() публичный статический Метод

Generate a policy document that describes custom access permissions to apply via a private distribution's signed URL.
public static BuildPolicyForSignedUrl ( string resourcePath, System.DateTime expiresOn, string limitToIpAddressCIDR ) : string
resourcePath string /// An optional HTTP/S or RTMP resource path that restricts which /// distribution and resource path will be accessible in a signed /// URL. For standard distributions the resource URL will be /// "http://" + distributionName + "/" + path (may /// also include URL parameters. For distributions with the HTTPS /// required protocol, the resource URL must start with /// "https://". RTMP resources do not take the form of a /// URL, and instead the resource path is nothing but the stream's /// name. The '*' and '?' characters can be used as a wildcards to /// allow multi-character or single-character matches /// respectively: ///
    ///
  • * : All distributions/objects will be accessible
  • ///
  • a1b2c3d4e5f6g7.cloudfront.net/* : All objects /// within the distribution a1b2c3d4e5f6g7 will be accessible
  • ///
  • a1b2c3d4e5f6g7.cloudfront.net/path/to/object.txt /// : Only the resource named path/to/object.txt in the /// distribution a1b2c3d4e5f6g7 will be accessible.
  • ///
/// If this parameter is null the policy will permit access to all /// distributions and resource path associated with the certificate /// keypair used to generate the signed URL. ///
expiresOn System.DateTime The time and date when the signed URL will expire.
limitToIpAddressCIDR string An optional range of client IP addresses that will be allowed /// to access the distribution, specified as a CIDR range. If /// null, the CIDR will be 0.0.0.0/0 and any client will /// be permitted.
Результат string
Пример #1
0
        /// <summary>
        /// Returns signed cookies that provides tailored access to private content based on an access time window and an ip range.
        /// </summary>
        /// <param name="resourceUrlOrPath">
        /// The URL or path for resource within a distribution.
        /// </param>
        /// <param name="privateKey">Your private key file. RSA private key (.pem) are supported.</param>
        /// <param name="keyPairId">The key pair id corresponding to the private key file given.</param>
        /// <param name="expiresOn">The expiration date till which content can be accessed using the generated cookies.</param>
        /// <param name="activeFrom">The date from which content can be accessed using the generated cookies.</param>
        /// <param name="ipRange">The allowed IP address range of the client making the GET request, in CIDR form (e.g. 192.168.0.1/24).</param>
        /// <returns>The signed cookies.</returns>
        public static CookiesForCustomPolicy GetCookiesForCustomPolicy(string resourceUrlOrPath,
                                                                       TextReader privateKey,
                                                                       string keyPairId,
                                                                       DateTime expiresOn,
                                                                       DateTime activeFrom,
                                                                       string ipRange)
        {
            var cookies = new CookiesForCustomPolicy();
            var policy  = AmazonCloudFrontUrlSigner.BuildPolicyForSignedUrl(resourceUrlOrPath, expiresOn,
                                                                            ipRange, activeFrom);

            var base64EncodedPolicy = AmazonCloudFrontUrlSigner.MakeStringUrlSafe(policy);

            cookies.Policy = new KeyValuePair <string, string>(PolicyKey, base64EncodedPolicy);

            RSAParameters rsaParameters = AmazonCloudFrontUrlSigner.ConvertPEMToRSAParameters(privateKey);

            byte[] signatureBytes = AmazonCloudFrontUrlSigner.SignWithSha1RSA(
                UTF8Encoding.UTF8.GetBytes(policy), rsaParameters);
            string urlSafeSignature = AmazonCloudFrontUrlSigner.MakeBytesUrlSafe(signatureBytes);

            cookies.Signature = new KeyValuePair <string, string>(SignatureKey, urlSafeSignature);

            cookies.KeyPairId = new KeyValuePair <string, string>(KeyPairIdKey, keyPairId);

            return(cookies);
        }