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
|
Using a .NET .snk Key File for RSA EncryptionDemonstrates 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).
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 |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.