Security is the most concerning factor of any application. Security is crucial where internet technology works. Java programing environment supports many security implementations in different ways. Java SDK 1.4 released with a core part called Java Cryptography Extension ( JCE ), provides various implementations and APIs for performing cryptographic operations in Java programming ,including encryption, key generation and agreement, and Message Authentication Code (MAC) algorithms etc. its also support different cryptographic technique including symmetric ,asymmetric ,block cypher etc. It is optional in earlier version , from JDK 1.4 it is integrated with JDK.
JCE Architecture
The Java Cryptography Extension ( JCE ) gives generic and vendor independent collection of APIs. So that each Vendor can then write their own different implementation (provider) of those APIs ,with different feature sets, performance characteristics, and costs. It is based on a provider basic architecture. The JCE basically has following components
  • Service-Engine
  • Abstract classes defined the functionalities of JCE , it is independent of different algorithms like symmetric , asymmetric etc.
  • Service Interface
  • High level abstract of service provided by different provided implementation.
  • Provider
  • Class which provide different implementations.
  • Security
  • The class which manipulate all the providers.
    Provider
         A provider is referred as the underlying implementation of a particular security mechanism in JCE . There are different companies which offer providers like IBM, Bouncy Castle, RSA etc. Implementations are available in the form of both free and as paid service. It is typically a package that provides the concrete implementation of cryptographic elements, including message digest algorithms, key store creation and management etc. Each provider has a name (e.g SUN) and developer can use the same name to request a particular object will gives the required service for the encryption process ( e.g DSA algorithm). The JCE framework authenticate the providers .
    Implementation
         JCE consists of different classes and interfaces to provide different features to java encryption
    programing. Developers can plug different providers to JCE and can use the features of each.

      Consider an example with Data Encryption Standard (DES) mechanism..
  • Generate Key
  • For creating key, we need an instance of KeyGenerator ,which has getInstance() method for it. You can pass the provider name as argument,specifying which implementation to use.
    KeyGenerator kgn = KeyGenerator.getInstance(“DES”);
    SecretKey ky = kgn.generateKey();
  • Generate Key
  • For creating key, we need an instance of KeyGenerator ,which has getInstance() method for it. You can pass the provider name as argument,specifying which implementation to use.
    KeyGenerator kgn = KeyGenerator.getInstance(“DES”);
    SecretKey ky = kgn.generateKey();
  • Generate Cipher
  • Generation of cipher is same as key ,here we can use getInstance() method of Cipher class. The method accept following parameter as argument separated by ‘/’.
    1. Algorithm name
    2. Mode (optional)
    3. Padding scheme (optional)
    Cipher cip =Cipher.getInstance(“DES/ECB/PKCS5Padding”); this will provides a DES algorithm, with the Electronic Codebook (ECB) mode with PKCS#5 style padding.
  • Message as Byte array
  • byte[] text = “my message”.getBytes();
  • Encrypt
  • cip.init(Cipher.ENCRYPT_MODE, ky);
    byte[] textEncrypted = cip.doFinal(text);
    the textEncrypted now contains the encrypted data now the data is ready to send over the network
  • Decrypt
  • The same key must be used to decrypt the data
    cip.init(Cipher.DECRYPT_MODE, ky);
    byte[] textDecrypted = cipher.doFinal(textEncrypted);
    now textDecrypted contains the decrypted (original) data.
    Secure Streams
        JCE also provide secure input and out functionalities . Using CipherInputStream/ CipherOutputStream – Using this classes we can read/write a stream of data and encrypt/decrypt it before reading and writing by any other resources in your application. It is resemble to file stream classes.

    Open source implementation
        There are many companies offering opensource JCE implementation.
  • Cryptix- (for JDK 1.1, 1.2, and 1.3. )
  • BouncyCastle p( for JDK 1.1, 1.2, and 1.3. )
  • The JCI has many advantages
  • Implementation independence and interoperability
  • Algorithm independence and extensibility
  • Adding third party provider in JCE is simple ,only need to create key and cipher with the provided implementation as an optional parameter.
  • Allow asymmetric cryptography
  • JCE is one of the powerful APIs in JAVA programming language, providing different encryption features there by solving security related issues.