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
AES Encrypt / URL Encode StringDownloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries This sample program demonstrates AES encrypt a string, creating a url-encoded encrypted string. // The Chilkat Encryption library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Encrypt and URL-encode a string.
void CryptExample(void)
{
CkCrypt2 crypt;
// Any string passed to UnlockComponent automatically begins the 30-day trial.
crypt.UnlockComponent("30-day trial");
// Use AES encryption.
crypt.put_CryptAlgorithm("aes");
// Use 128-bit AES encryption.
// It is also possible to use 192-bit or 256-bit AES encryption.
crypt.put_KeyLength(128);
// Create a binary secret key from a password string.
CkByteData secretKey;
crypt.GenerateSecretKey("myPassword",secretKey);
crypt.put_SecretKey(secretKey);
// Note: we could just as well set the binary secret key directly.
// We need a binary key of 16 bytes (16 bytes * 8 bits/byte = 128 bits)
// Example:
// int i;
// unsigned char sKey[16];
// for (i=0; i<16; i++) sKey[i] = i;
// secretKey.append(sKey,16);
// Set the output string encoding to "URL"
crypt.put_EncodingMode("url");
// Encrypt a string.
// NOTE: AES encryption pads to a multiple of 16 bytes.
CkString strEncrypted;
crypt.EncryptStringENC("ABCD1234",strEncrypted);
printf("strEncrypted = [%s]\n",strEncrypted.getString());
// Now decrypt it:
CkString strDecrypted;
crypt.DecryptStringENC(strEncrypted.getString(),strDecrypted);
printf("strDecrypted = [%s]\n",strDecrypted.getString());
// PRINTS:
// strEncrypted = [%0D%C2%D7Am%F1d%08e%B3%00%8Fu%AB%DE%FF]
// strDecrypted = [ABCD1234]
|
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.