Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 703575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:50:47+00:00 2026-05-14T03:50:47+00:00

Has anyone using .net actually worked out how to successfully sign a signature to

  • 0

Has anyone using .net actually worked out how to successfully sign a signature to use with CloudFront private content? After a couple of days of attempts all I can get is Access Denied.

I have been working with variations of the following code and also tried using OpenSSL.Net and AWSSDK but that does not have a sign method for RSA-SHA1 yet.

The signature (data) looks like this

{"Statement":[{"Resource":"http://xxxx.cloudfront.net/xxxx.jpg","Condition":​{"DateLessThan":​{"AWS:EpochTime":1266922799}}}]}

Update: Solved all of this by removing a single space in the above signature.

If only I had noticed it earlier!

This method attempts to sign the signature for use in the canned url. So of the variations have included chanding the padding used in the has and also reversing the byte[] before signing as apprently OpenSSL do it this way.

public string Sign(string data)
{
   using (SHA1Managed SHA1 = new SHA1Managed())
   {
      RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
      RSACryptoServiceProvider.UseMachineKeyStore = false;

      // Amazon PEM converted to XML using OpenSslKey
      provider.FromXmlString("<RSAKeyValue><Modulus>....."); 

      byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data);

      byte[] hash = SHA1.ComputeHash(plainbytes);
      //Array.Reverse(sig); // I have see some examples that reverse the hash

      byte[] sig = provider.SignHash(hash, "SHA1");

     return Convert.ToBase64String(sig);
   }
}

It’s useful to note that I have verified the content is setup correctly in S3 and CloudFront by generating a CloudFront canned policy url using my CloudBerry Explorer. How do they do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:50:47+00:00Added an answer on May 14, 2026 at 3:50 am

    Here is the full code if anyone if interested:

    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"":""<url>"",""Condition"":{""DateLessThan"":{""AWS:EpochTime"":<expiration>}}}]}".
                    Replace( "<url>", url ).
                    Replace( "<expiration>", expirationEpoch );
    
    
            string signature = GetUrlSafeString( Sign( policy ) );
    
            return url + string.Format("?Expires={0}&Signature={1}&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");
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone had experience using SSL with net.tcp binding in WCF? Ive read its
Has anyone successfully used the AJAX-enabled ASP.NET Web Application wizard in Delphi 2007 to
Has anyone tried using the NHibernate Velocity L2 cache provider against the Azure AppFabric
Has Anyone tried using PDF in iPad Application, using CGPDf functions. I have used
Has anyone succeeded in using Squeryl's externalTransactionManagementAdapter with play framework 2.0?: object Global extends
Has anyone had any experience using Adobe Air to create BitTorrent application? Is there
Has anyone ever tried sending emails using 1&1 smtp host? I tried the following?
Has anyone had any experiences developing large Java applications using GNU gettext for internationalization?
Has anyone tried to back up a SharePoint web application using forms based authentication
Has anyone had any experience of talking between an iSeries (using IBM's Websphere MQ)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.