Create Amazon CloudFront Signed URL in VBScript (for ASP)

This sample code snippet is graciously provided by a Chilkat customer:

See Also: Chilkat RSA ActiveX Reference Documentation

...

resource = "http://*********.cloudfront.net/something.jpg"

'Expiration
expiration = 1278680686

'Policy
policy = "{""Statement"":[{""Resource"":""" &  resource & _
    """,""Condition"":{""DateLessThan"":{""AWS:EpochTime"":" & _
   expiration & "}}}]}"

'Chilkat Component
set pkey = Server.CreateObject("Chilkat.PrivateKey")

'Load the private key from an RSA PEM file:
private_key = pkey.LoadPemFile("c:\pk-xxx.pem")

'Get the private key in XML format:
private_key = pkey.GetXml()

set rsa = Server.CreateObject("Chilkat.Rsa")

'Any string argument automatically begins the 30-day trial.
success = rsa.UnlockComponent("30-day trial")
If (success <> 1) Then
    response.write("RSA component unlock failed<br><br>")
End If

'Import the private key into the RSA component:
success = rsa.ImportPrivateKey(private_key)
If (success <> 1) Then
    response.write("Error: " & rsa.LastErrorText & "<br><br>")
End If

rsa.Charset = "utf-8"
rsa.EncodingMode = "base64"
rsa.LittleEndian = 0
signature = rsa.SignStringENC(policy,"sha-1")

'UrlSafe
signature = Replace(signature,"+","-")
signature = Replace(signature,"=","_")
signature = Replace(signature,"/","~")

signedUrl = "" & resource & "?Expires=" & expiration & "&Signature=" & signature & _
    "&Key-Pair-Id=" & key_pair_id

response.write("<img src=""" & signedUrl & """ />")

set pkey = nothing
set rsa = nothing

...