Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
HMAC SHA1 for Amazon S3Demonstrates the HMAC SHA1 computation required by the Amazon S3 web service.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) -- This example uses sample data from: -- http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAuthentication.html DECLARE @strToSign nvarchar(4000) ERROR-CONCAT SELECT @strToSign = 'GET' + CHAR(10) + CHAR(10) + CHAR(10) + 'Tue, 27 Mar 2007 19:36:42 +0000' + CHAR(10) + '/johnsmith/photos/puppy.jpg' DECLARE @crypt int EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @crypt, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success <> 1 BEGIN -- Unlock Failed. EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- We want SHA1 for the HMAC hash algorithm: EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha1' DECLARE @AWSAccessKeyId nvarchar(4000) SELECT @AWSAccessKeyId = '0PN5J17HBGZHT7JJ3X82' DECLARE @AWSSecretAccessKey nvarchar(4000) SELECT @AWSSecretAccessKey = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o' -- Set the HMAC secret key: EXEC sp_OAMethod @crypt, 'SetHmacKeyString', NULL, @AWSSecretAccessKey -- By setting the charset = "utf-8", the string will be converted -- to utf-8 (internal to the Chilkat component) prior to signing: EXEC sp_OASetProperty @crypt, 'Charset', 'utf-8' -- Indicate that Base64 output is desired: EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64' DECLARE @signature nvarchar(4000) EXEC sp_OAMethod @crypt, 'HmacStringENC', @signature OUT, @strToSign EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 -- Display the signature as part of the HTTP Authorization header: PRINT 'Authorization: AWS ' + @AWSAccessKeyId + ':' + @signature PRINT 'Expected: AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA=' END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.