Visual C++ Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Duplicate Java's PBEWithMD5AndDES

Demonstrate's how to duplicate Java's PBEWithMD5AndDES.

Downloads:

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
#include <CkCrypt2.h>

void ChilkatSample(void)
    {
    CkCrypt2 crypt;

    bool success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("%s\n",crypt.lastErrorText());
        return;
    }

    crypt.put_CryptAlgorithm("pbes1");
    crypt.put_PbesPassword("secret");

    crypt.put_PbesAlgorithm("des");
    crypt.put_KeyLength(64);

    //  The salt for PBKDF1 is always 8 bytes:
    crypt.SetEncodedSalt("C773218C7EC8EE99","hex");

    crypt.put_IterationCount(20);

    //  A hash algorithm needs to be set for PBES1:
    crypt.put_HashAlgorithm("md5");

    //  Indicate that the encrypted bytes should be returned
    //  as a hex string:
    crypt.put_EncodingMode("hex");

    const char * plainText;
    plainText = "This is another example";

    const char * encryptedText;
    encryptedText = crypt.encryptStringENC(plainText);

    //  The output should be: E729548140D20B14E9140F832A7E980AA449A84B295C75CE
    printf("%s\n",encryptedText);

    //  Now decrypt:
    const char * decryptedText;
    decryptedText = crypt.decryptStringENC(encryptedText);

    printf("%s\n",decryptedText);

    //  ----------------------------------------------------------------
    //  ----------------------------------------------------------------
    //  
The code above duplicates this Java JCE example:

	public static void main(String args[]) throws Exception
	{
	    PBEKeySpec pbeKeySpec;
	    PBEParameterSpec pbeParamSpec;
	    SecretKeyFactory keyFac;

	    // Salt
	    byte[] salt = {
		(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
		(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
	    };

	    // Iteration count
	    int count = 20;

	    // Create PBE parameter set
	    pbeParamSpec = new PBEParameterSpec(salt, count);

	    String password = "secret";
	    pbeKeySpec = new PBEKeySpec(password.toCharArray());
	    keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
	    SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

	    // Create PBE Cipher
	    Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");

	    // Initialize PBE Cipher with key and parameters
	    pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

	    // Our cleartext
	    byte[] cleartext = "This is another example".getBytes();
	    
	    // Encrypt the cleartext
	    byte[] ciphertext = pbeCipher.doFinal(cleartext);
	    
     	System.out.print("ciphertext: ");
        System.out.println(toHex(ciphertext));
	}

    }

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

Mail Component · .NET Mail Component · XML Parser