?
Solved

DES Algorithm Example needed

Posted on 2004-08-29
6
Medium Priority
?
1,339 Views
Last Modified: 2010-05-18
Hello All,

I need to encrypt an Object using DES.  Please let me know is this possible if it is possible with java jdk tool kit

thanks
moneymama
0
Comment
Question by:moneymama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11927742
use javax.cryto package

0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 1000 total points
ID: 11927744
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 12

Expert Comment

by:Giant2
ID: 11928900
To use the crypto package you must have JCE.
This is contained automatically with jdk1.4 (and greater).
This is downloadable from www.java.sun.com for previous jdk (see java Sun and JCE package)

If you want to build your own the implementation of DES algorithm you must study it before all and you can even not use the crypto package of JCE.


Bye, Giant.
0
 

Expert Comment

by:rafiek
ID: 11929625
here's an example, i hope it helps...i had to implement it from scratch for an assigment...but using the javax package is so much more simpler, so use what is available to you.

//EXAMPLE

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.Cipher;

public class SymmetricCipherTest {
  private static byte[] iv =
      { 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c, 0x0d };

  private static byte[] encrypt(byte[] inpBytes,
      SecretKey key, String xform) throws Exception {
    Cipher cipher = Cipher.getInstance(xform);
    IvParameterSpec ips = new IvParameterSpec(iv);
    cipher.init(Cipher.ENCRYPT_MODE, key, ips);
    return cipher.doFinal(inpBytes);
  }

  private static byte[] decrypt(byte[] inpBytes,
      SecretKey key, String xform) throws Exception {
    Cipher cipher = Cipher.getInstance(xform);
    IvParameterSpec ips = new IvParameterSpec(iv);
    cipher.init(Cipher.DECRYPT_MODE, key, ips);
    return cipher.doFinal(inpBytes);
  }

  public static void main(String[] unused) throws Exception {
    String xform = "DES/ECB/PKCS5Padding";
    // Generate a secret key
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    kg.init(56); // 56 is the keysize. Fixed for DES
    SecretKey key = kg.generateKey();

    byte[] dataBytes =
        "J2EE Security for Servlets, EJBs and Web Services".getBytes();

    byte[] encBytes = encrypt(dataBytes, key, xform);
    byte[] decBytes = decrypt(encBytes, key, xform);

    boolean expected = java.util.Arrays.equals(dataBytes, decBytes);
    System.out.println("Test " + (expected ? "SUCCEEDED!" : "FAILED!"));
  }
}
0
 

Author Comment

by:moneymama
ID: 11929984
thanks for ur inputs.

Basically I need to encrypt and decrypt the objects.

thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question