Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the full code if anyone if interested:</p> <pre><code>internal class CloudFrontSecurityProvider { private readonly RSACryptoServiceProvider privateKey; private readonly string privateKeyId; private readonly SHA1Managed sha1 = new SHA1Managed(); public CloudFrontSecurityProvider(string privateKeyId, string privateKey) { this.privateKey = new RSACryptoServiceProvider(); RSACryptoServiceProvider.UseMachineKeyStore = false; this.privateKey.FromXmlString( privateKey ); this.privateKeyId = privateKeyId; } private static int GetUnixTime(DateTime time) { DateTime referenceTime = new DateTime(1970, 1,1); return (int) (time - referenceTime).TotalSeconds; } public string GetCannedUrl(string url, DateTime expiration) { string expirationEpoch = GetUnixTime( expiration ).ToString(); string policy = @"{""Statement"":[{""Resource"":""&lt;url&gt;"",""Condition"":{""DateLessThan"":{""AWS:EpochTime"":&lt;expiration&gt;}}}]}". Replace( "&lt;url&gt;", url ). Replace( "&lt;expiration&gt;", expirationEpoch ); string signature = GetUrlSafeString( Sign( policy ) ); return url + string.Format("?Expires={0}&amp;Signature={1}&amp;Key-Pair-Id={2}", expirationEpoch, signature, this.privateKeyId); } private static string GetUrlSafeString(byte[] data) { return Convert.ToBase64String( data ).Replace( '+', '-' ).Replace( '=', '_' ).Replace( '/', '~' ); } private byte[] Sign(string data) { byte[] plainbytes = Encoding.UTF8.GetBytes(data); byte[] hash = sha1.ComputeHash(plainbytes); return this.privateKey.SignHash(hash, "SHA1"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload