title: AWS signature version 4 signing key issue ruby
body: <p>Has to be done in ruby
  my code is:</p>
  <pre><code>require &quot;openssl&quot;
  require &quot;time&quot;
  require &quot;uri&quot;
  require &quot;pathname&quot;
  
  def getSignatureKey (key, dateStamp, regionName, serviceName)
    digest= OpenSSL::Digest.new('sha256')
    kDate = OpenSSL::HMAC.hexdigest(digest, (&quot;AWS4&quot; + key), dateStamp)
    puts(&quot;kdate:  #{kDate}&quot;)
    kRegion = OpenSSL::HMAC.hexdigest(digest, kDate, regionName)
    puts(&quot;kRegion:  #{kRegion}&quot;)
    kService = OpenSSL::HMAC.hexdigest(digest, kRegion, serviceName)
    puts(&quot;kService:  #{kService}&quot;)
    kSigning = OpenSSL::HMAC.hexdigest(digest, kService, &quot;aws4_request&quot;)
    puts(&quot;kSigning:  #{kSigning}&quot;)
    kSigning
  end
  
  key = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'
  dateStamp = '20120215'
  regionName = 'us-east-1'
  serviceName = 'iam'
  
  
  puts(&quot;===========================================OUTPUT IS: ==============================================&quot;)
  getSignatureKey(key,dateStamp,regionName,serviceName)
  </code></pre>
  <p>which produces the output:</p>
  <p><strong>kdate</strong>: 969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d
  <strong>kRegion</strong>:a59e30f9d899c47b3dd68ea1c0ab3bb529e03a8f4ed2f54cb64af547330a22a0
  <strong>kService</strong>:e33cbcda009243ed24c04af249a477d33b33c97ba7717327636afab2c6e6ef78
  <strong>kSigning</strong>:9d8a8749deaee911a4ed0d04fb34af903f690d0423c146023bd282ba8ebf955b</p>
  <p>however the output should be, according to aws documentation: <a href="https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html</a>):</p>
  <p><strong>kdate</strong>:  969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d
  <strong>kRegion</strong>:69daa0209cd9c5ff5c8ced464a696fd4252e981430b10e3d3fd8e2f197d7a70c
  <strong>kService</strong>:f72cfd46f26bc4643f06a11eabb6c0ba18780c19a8da0c31ace671265e3c87fa
  <strong>kSigning</strong>:f4780e2d9f65fa895f9c67b32ce1baf0b0d8a43505a000a1a9e090d414db404d</p>
  <p>so the kdate matches but the others do not, I haven't miss-spelled &quot;us-east-1&quot; so I'm really not sure why they don't match. If anyone could offer advice I'd be very grateful.</p>