SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

HMAC SHA1 for Amazon S3

Demonstrates the HMAC SHA1 computation required by the Amazon S3 web service.

Download Chilkat Crypt ActiveX

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.