there are many key words in java cryptography and none of them is been recognized in my system.
Is there any way i can implement java cryptography...?

Recommended Answers

All 4 Replies

I am trying to build an application using JAVA.
Well the application is more like encrypting the message and communicating over a medium.(wired netowork/wireless)
so i came across the JCE (java cryptographic engine) but none of those programs were working in my system , well none of the keywords or objects which i created was recognized by my system, dont know wat to do?

Can I see the code you wrote before?
Here is a java code. (tested)

import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;

public class Test{
  public static void main(String args[]) throws Exception {
     String pass="abcdefgh"; // greater then 7 chars.

    // Create Key
    byte key[] = pass.getBytes();
    DESKeySpec desKeySpec = new DESKeySpec(key);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    SecretKey secretKey = keyFactory.generateSecret(desKeySpec);

    // Create Cipher
    Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
    desCipher.init(Cipher.ENCRYPT_MODE, secretKey);

    // Create stream
    FileOutputStream fos = new FileOutputStream("out.des");
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    CipherOutputStream cos = new CipherOutputStream(bos, desCipher);
    ObjectOutputStream oos = new ObjectOutputStream(cos);

    // Write somethind
    oos.writeUTF("Hello World");
    oos.writeInt(100);
    oos.flush();
    oos.close();

    // Change cipher mode
    desCipher.init(Cipher.DECRYPT_MODE, secretKey);

    // Create stream
    FileInputStream fis = new FileInputStream("out.des");
    BufferedInputStream bis = new BufferedInputStream(fis);
    CipherInputStream cis = new CipherInputStream(bis, desCipher);
    ObjectInputStream ois = new ObjectInputStream(cis);

    String message=ois.readUTF();
    int no = ois.readInt();
    ois.close();
    System.out.println("Message : " + message );
    System.out.println("No : " + no);
     
  }
}

well since i use netbeans IDE , whenever i mention any of the keywords belonging to java cryptography , they give a syntax error .

But the above code mentioned is working perfectly fine .
Thanks.

Is there ne way that i can fix the netbeans IDE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.