This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Please send me one example of Encryption/Decryption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Please send me one example of Encryption/Decryption" Watch "Please send me one example of Encryption/Decryption" New topic
Author

Please send me one example of Encryption/Decryption

Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
please send me JCE encryption/decryption example


Senior software engineer
Jayanthimeena
Greenhorn

Joined: Jul 24, 2001
Posts: 17
Hai
what JCE means??
raghavender rao
Ranch Hand

Joined: Jul 20, 2001
Posts: 45
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

Rao<BR>Sun Certified Programmer for the Java��� 2 Platform
Srinath R
Ranch Hand

Joined: Jun 28, 2000
Posts: 71
Hi Raghavender
can u pl. tell from which site we have to download the package com.dstc.* package
srinath


[This message has been edited by srinath rammohan (edited September 11, 2001).]
Laurent Leonard
Ranch Hand

Joined: May 15, 2001
Posts: 35
Guess what! You have your answer in your question !!!
try www.dstc.com
When you choose a prefix for a package, it's recommended by sun
to use the address site in the reverse order (without www).
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be


Laurent LEONARD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please send me one example of Encryption/Decryption
 
Similar Threads
Regarding source code - elliptic curve cryptography
BouncyCastle for J2ME (RC4)
simple Encryption and Decryption which works in jdk 1.2x
Implementing encryption and decryption in java
Password based encryption