Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
EncryptEncoded: Decode-->Encrypt Bytes-->EncodeIn some programming languages, it is very difficult to work with binary data. To help avoid these problems, two new methods have been added to the Chilkat Crypt2 component: EncryptEncoded and DecryptEncoded. EncryptEncoded takes binary data in the form of an encoded string (base64, hex, etc.), decodes it, encrypts, and then encodes the encrypted output and returns an encoded string (base64, hex, etc.). DecryptEncoded does the opposite. It accepts encrypted data in the form of an encoded string, decodes, decrypts, and then returns the result as an encoded string. The encoding is determined by the EncodingMode property. It may be "base64", "hex", "url", "quoted-printable", etc. Note: The EncryptEncoded and DecryptEncoded methods are unreleased at the time of this writing (08-April-2008) The next major Chilkat Crypt2 release after this date will include these new methods.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) 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 EXEC sp_OASetProperty @crypt, 'CryptAlgorithm', 'aes' EXEC sp_OASetProperty @crypt, 'KeyLength', 128 -- The encrypted output will be a hex-encoded string. -- It is also possible to use "base64", "url" (for url-encoding), and other modes. EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hex' -- Both ECB and CBC modes are available. -- Use "ecb" for Electronic Cookbook Mode. -- "cbc" is for Cipher-Block-Chaining. EXEC sp_OASetProperty @crypt, 'CipherMode', 'ecb' -- Key (128): E8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA -- Plaintext: 014BAF2278A69D331D5180103643E99A -- Ciphertext: 6743C3D1519AB4F2CD9A78AB09A511BD EXEC sp_OAMethod @crypt, 'SetEncodedKey', NULL, 'E8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA', 'hex' EXEC sp_OASetProperty @crypt, 'PaddingScheme', 3 DECLARE @cipherHex nvarchar(4000) DECLARE @plainTextHex nvarchar(4000) EXEC sp_OAMethod @crypt, 'EncryptEncoded', @cipherHex OUT, '014BAF2278A69D331D5180103643E99A' PRINT @cipherHex EXEC sp_OAMethod @crypt, 'DecryptEncoded', @plainTextHex OUT, @cipherHex PRINT @plainTextHex END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.