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
|
Encrypt URL Query ParametersDemonstrates how to encrypt URL query parameters. Query parameter values are encrypted using AES encryption and then base64 encoded. Base64 encoding is the most efficient means of transforming binary data into printable chars. In Base64 encoding, 4 printable chars represent 3 binary bytes. Therefore, the size of the output is expanded by 4/3rds. In addition, the output of AES encryption is always padded to a multiple of 16 bytes (prior to base64 encoding). One issue with Base64 encoding is that the following alphabet is used: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ The "+" and "/" characters would disrupt a URL. Therefore, you'll want to URL-encode the base64 output. This example shows how to do it, and then how to reverse the process. PS> The Base64 encoding algorithm may also include one or two "=" characters at the very end of the encoded data, and this would also disrupt a URL...
LOCAL loCrypt LOCAL lnSuccess LOCAL lcFieldOne LOCAL lcE1 LOCAL lcE2 LOCAL lcUrl LOCAL lcD2 LOCAL lcD1 loCrypt = CreateObject('Chilkat.Crypt2') * We want to arrive at a URL with encrypted query parameter * values, such as: * www.chilkatsoft.com/login?fieldOne=xxxxxxxxxxxx&fieldTwo=xxxxxxxxxxxx&fieldThree=xxxxxxxxxxx&fieldFour=xxxxxxxxxxx * Any string argument automatically begins the 30-day trial. lnSuccess = loCrypt.UnlockComponent("30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF lcFieldOne = "This is a test" loCrypt.CryptAlgorithm = "aes" * The default cipher mode is CBC (Cipher Block Chaining) * We'll use ECB here because the amount of data to be * encrypted is small anyway... loCrypt.CipherMode = "ecb" * AES supports 128, 192, and 256-bit encryption. loCrypt.KeyLength = 128 * We need a 16-byte secret key (i.e. 128 bits) loCrypt.SetEncodedKey("000102030405060708090A0B0C0D0E0F","hex") loCrypt.EncodingMode = "base64" lcE1 = loCrypt.EncryptStringENC(lcFieldOne) ? lcE1 * Let's URL encode it: loCrypt.CryptAlgorithm = "none" loCrypt.EncodingMode = "url" * Because the encryption algorithm = "none", it's a simple * pass-through with encoding... lcE2 = loCrypt.EncryptStringENC(lcE1) ? lcE2 * Now form the URL: lcUrl = "http://www.chilkatsoft.com/login?fieldOne=" + lcE2 ? lcUrl * Now reverse the process: loCrypt.CryptAlgorithm = "none" loCrypt.EncodingMode = "url" lcD2 = loCrypt.DecryptStringENC(lcE2) * Back to base64: ? lcD2 * Now back to the original string: loCrypt.CryptAlgorithm = "aes" loCrypt.EncodingMode = "base64" lcD1 = loCrypt.DecryptStringENC(lcD2) ? lcD1 * A final note: If decrypting in ASP or ASP.NET, * depending on what you're doing, * you may not need the explicit URL-decoding step. * It may be that ASP already did the URL decoding when you * fetch the query parameter value. If so, you only need * to decrypt using base64 for the encoding mode. |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser