Java Examples

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

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

AES String Encryption

AES string encryption in Java.

 Chilkat Java Library Downloads for Windows, Linux, and MAC OS X

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkCrypt2 crypt = new CkCrypt2();

    boolean success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        System.out.println("Crypt component unlock failed");
        return;
    }

    String password;
    password = "secretPassPhrase";

    crypt.put_CryptAlgorithm("aes");
    crypt.put_CipherMode("cbc");
    crypt.put_KeyLength(128);

    //  Generate a binary secret key from a password string
    //  of any length.  For 128-bit encryption, GenEncodedSecretKey
    //  generates the MD5 hash of the password and returns it
    //  in the encoded form requested.  The 2nd param can be
    //  "hex", "base64", "url", "quoted-printable", etc.
    String hexKey;
    hexKey = crypt.genEncodedSecretKey(password,"hex");
    crypt.SetEncodedKey(hexKey,"hex");

    crypt.put_EncodingMode("base64");
    String 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.
    String encText;
    encText = crypt.encryptStringENC(text);

    System.out.println(encText);

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

    System.out.println(decryptedText);
  }
}

 

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