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

Verify Java Signature

Demonstrates how to verify a digital signature produced by Java.
The Java code that produces a digital signature that can be verified with
this Chilkat example is found at: http://www.cknotes.com/?p=283

Download 32-bit Chilkat RSA ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)

    DECLARE @pubKey int
    EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  Load an RSA public key from an ASN.1 DER file
    EXEC sp_OAMethod @pubKey, 'LoadRsaDerFile', @success OUT, 'pubKey.der'

    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
        RETURN
      END

    DECLARE @pkeyXml nvarchar(4000)

    --  Get the public key in XML format:
    EXEC sp_OAMethod @pubKey, 'GetXml', @pkeyXml OUT

    DECLARE @rsa int
    EXEC @hr = sp_OACreate 'Chilkat.Rsa', @rsa OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Any string argument automatically begins the 30-day trial.

    EXEC sp_OAMethod @rsa, 'UnlockComponent', @success OUT, '30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rsa, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
        RETURN
      END

    --  Import the public key into the RSA component:
    EXEC sp_OAMethod @rsa, 'ImportPublicKey', @success OUT, @pkeyXml
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rsa, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
        RETURN
      END

    EXEC sp_OASetProperty @rsa, 'EncodingMode', 'base64'

    DECLARE @strData nvarchar(4000)

    SELECT @strData = 'The quick brown fox jumps over the lazy dog'

    --  IMPORTANT:  This Base64 signature will have to be updated
    --  with the digital signature produced by the Java code at:
    --  http://www.cknotes.com/?p=283
    DECLARE @base64Sig nvarchar(4000)

    SELECT @base64Sig = 'VGV5A+bodHBpBwwJZdf17Bv+lkBTm/gteOf8iCgEEfNzBosZLaAB8X55BIZIkE2zKRXoMcJT+iCxsj+1hnlwJeKZ+Gya58lrHw6NWm2N0O/KyfnuEzADOM86X0xrkgdFT6SYpbZ9dWPC59NiHeEdVyjOXNJ3fBpUSQ5/5pvVWm0='

    --  Verify the signature produced by the Java code at:
    --  http://www.cknotes.com/?p=283
    --  The VerifyStringENC method hashes the input data and verifies
    --  the hash against the signature.
    EXEC sp_OAMethod @rsa, 'VerifyStringENC', @success OUT, @strData, 'sha-1', @base64Sig
    --  Is the signature verified?
    IF @success = 1
      BEGIN

        PRINT 'Signature Verified!'
      END
    ELSE
      BEGIN

        PRINT 'Signature not verified!'
      END

END
GO

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.