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
|
Verify Java SignatureDemonstrates how to verify a digital signature produced by Java.
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.