hi ther ...
the below code wil work when u download com.dstc.* package
import java.io.*;
import com.dstc.security.provider.DSTC;
import javax.crypto.*;
import javax.crypto.Cipher.*;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import java.security.Provider.*;
public class EncTest {
public static void main(
String args[]){
//String text = "Hello";
try {
Security.addProvider(new DSTC());
String text = "RAO";
//Provider pp = new
System.out.println();
System.out.println();
System.out.println("Generating a DESede (TripleDES) key...");
// Create a TripleDES key
System.out.println();
System.out.println();
//KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyStore.getDefaultType());
KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
//KeyGenerator keyGenerator = KeyGenerator.getInstance("PBEwithMD5andDE5-CBC");
keyGenerator.init(56); // need to initialize with the keysize
Key key = keyGenerator.generateKey();
String keyy = key.toString();
System.out.println();
System.out.println();
System.out.println("Done generating the key and the key is ... "+keyy);
//System.out.println("The Security Manager is"+System.getSecurityManager());
//Create a cipher using that key to initialize it
// Cipher cipher = Cipher.getInstance("PBEwithMD5andDE5-CBC");
Cipher cipher = Cipher.getInstance("DES");
System.out.println();
System.out.println();
System.out.println("The Given Text is "+text);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] plaintext = text.getBytes("UTF8");
// Print System.out the bytes of the plaintext
//System.out.println("\nPlaintext: "+plaintext);
for (int i=0;i<plaintext.length;i++) {
System.out.print(plaintext[i]+" ");
}
// Perform the actual encryption
byte[] ciphertext = cipher.doFinal(plaintext);
// Print System.out the ciphertext
System.out.print("\n\nCiphertext: ");
String s=null;
for (int i=0;i<ciphertext.length;i++) {
System.out.print(ciphertext[i]+" ");
}
System.out.println();
System.out.println();
s = ciphertext.toString();
System.out.println("The CypherText is "+s);
// Re-initialize the cipher to decrypt mode
cipher.init(Cipher.DECRYPT_MODE, key);
// Perform the decryption
byte[] decryptedText = cipher.doFinal(ciphertext);
String output = new String(decryptedText,"UTF8");
System.out.println();
System.out.println();
System.out.println("\n\nDecrypted text: "+output);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
JCE stands for
Java Cryptography Extension
Rao...
mail me back