SQL Server Stored Procedure Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
FTP
HTML-to-XML
HTTP
MHT
MIME
RSA Encryption
Socket
Spider
String
Tar
Upload
XML
XMP
Zip

Byte Array
RSS
Atom
Self-Extractor

Using a .NET .snk Key File for RSA Encryption

Demonstrates how to load and use a .NET .snk key file for RSA encryption. SNK files are created by the Microsoft .NET Strong Name Tool (Sn.exe).

Download Chilkat RSA ActiveX

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

    DECLARE @success int

    EXEC sp_OAMethod @rsa, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success <> 1
      BEGIN
        PRINT 'RSA component unlock failed'
        RETURN
      END

    --  Load a public/private key pair from a .snk key file.
    DECLARE @xmlKey nvarchar(4000)

    EXEC sp_OAMethod @rsa, 'SnkToXml', @xmlKey OUT, 'chilkat2.snk'


    PRINT @xmlKey

    --  The xmlKey contains both public and private keys.
    --  Import either the public or private for encrypting or
    --  decrypting.
    EXEC sp_OAMethod @rsa, 'ImportPrivateKey', NULL, @xmlKey

    DECLARE @bUsePrivateKey int

    SELECT @bUsePrivateKey = 1
    DECLARE @encryptedText nvarchar(4000)

    EXEC sp_OAMethod @rsa, 'EncryptStringENC', @encryptedText OUT, 'Hello World!', @bUsePrivateKey


    PRINT @encryptedText

    --  Now decrypt with the public key:
    EXEC sp_OAMethod @rsa, 'ImportPublicKey', NULL, @xmlKey
    SELECT @bUsePrivateKey = 0
    DECLARE @decryptedText nvarchar(4000)

    EXEC sp_OAMethod @rsa, 'DecryptStringENC', @decryptedText OUT, @encryptedText, @bUsePrivateKey


    PRINT @decryptedText

    --  Note: We could have just as well encrypted using the public key
    --  and decrypted using the private key.

END
GO

 

Need a specific example? Send a request to support@chilkatsoft.com

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