Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

 

ASCII / ANSI Secret Key in Symmetric Encryption

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

Using an ASCII (or ANSI) secret key w/ symmetric encryption: AES, Blowfish, Twofish, RC2, 3DES, etc.

Download Chilkat C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C++ Libraries for VC++ 6.0 / Win32

#include <CkCrypt2.h>
#include <CkString.h>

void ChilkatSample(void)
    {
    CkCrypt2 crypt;

    bool success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("Crypt component unlock failed\n");
        return;
    }

    //  A frequent support question goes something like this:
    //  ------------------
    //  I am not able to decrypt strings encrypted using
    //  cryptix.jce.provider.key.RawSecretKey (Java) like I would normally do.

    // The key generation is being done with the Rijndael algorithm (256-bit)
    //  The AES encryption algorithm is "Rijndael/ECB/PKCS#5"

    //  The 32 character source key I'm using is this:
    //  1234567890123456789012345678912
    // 
    //  ------------------
    //  The customer tries to call GenerateSecretKey to
    //  convert the 32-character source key to a binary secret key,
    //  but this is incorrect (in this case).  GenerateSecretKey
    //  hashes a string of any length and produces binary hash output
    //  that is of the appropriate size to be used as a secret key.

    //  The telltale sign is that in this case, the string is the exact
    //  length of the secret key.  32 ANSI characters = 256 bits.
    //  Therefore, it is obvious that the bytes of the binary
    //  secret key should be the exact ascii character values
    //  of the string.

    CkString encKey;
    encKey = "1234567890123456789012345678912";

    crypt.put_CryptAlgorithm("aes");
    //  Mode is "ecb" or "cbc"
    crypt.put_CipherMode("ecb");
    crypt.put_KeyLength(256);

    //  Call SetEncodedKey with "ascii" to tell the component
    //  to use the ascii-bytes as the binary secret key.
    //  Make sure you call this after setting the KeyLength.
    crypt.SetEncodedKey(encKey,"ascii");

    crypt.put_EncodingMode("base64");
    CkString text;
    text = "The quick brown fox jumped over the lazy dog.";

    //  Encrypt a string and return the binary encrypted data
    //  in a base-64 encoded string.
    CkString encText;
    encText = crypt.encryptStringENC(text);

    printf("%s\n",(const char *)encText);

    //  Decrypt and show the original string:
    CkString decryptedText;
    decryptedText = crypt.decryptStringENC(encText);

    printf("%s\n",(const char *)decryptedText);
    }

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

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

Mail Component · .NET Mail Component · XML Parser