You are on page 1of 9

Membuat Program Java Enkripsi Applet

06.56 AJI SUKMA SEJATI NO COMMENTS

Ini adalah cara membuat suatu Program Enkripsi dengan Java Applet. Nah, bagi suka dengan Java, mungkin inilah hal yang perlu agan coba. Nah, langsung simak penejelasan saya.... Nanti program jadinya akan terlihat seperti ini:

================================================================================ =

BufferedInputStream. import java.io. . Buat dulu file Java Applet dan beri nama file tersebut pada pagkage agan 2.InputStreamReader.File.io.DataInputStream. cara membuat program tersebut adalah sebagai berikut: 1.io.FileNotFoundException.. import java.io.Nah.BufferedReader.io. import java. import java.io.io. import java. Lalu buat tampilan seperti diatas ================================================================================ 4. import java.FileInputStream.. import java. Setelah itu masukkan codingnya:  Masukkan coding ini dibawah pagkage.

txt".JFileChooser. public String text.logging. import javax.Logger."Informasi".FileWriter.addChoosableFileFilter(new jenisFile(EXT)). import javax.setTitle("Untitled . final String[] EXT = { ".NoSuchAlgorithmException. private void msg(String pesan) { JOptionPane.JOptionPane.swing.swing.util.io. import javax. import java. File file. import java.namafiletext.swing.NOTES").logging. import javax.PrintWriter. import java.csv" }. import java. //variabel fileBaru diinisialisai dengan TRUE fileBaru = true.FileFilter. //Filter Bawaan (All Files) di disable-kan fc.addChoosableFileFilter(new jenisFile(EXT2)).pesan.Level. fc. import java. import java.security.JFrame { public ta_java() { initComponents().io. import java.  Lalu tulis method2 yang dibutuhkan berikut: public class ta_java extends javax.*.IOException.security.io.showMessageDialog(this.import java.INFORMATION_MESSAGE). JOptionPane. import java. import javax.util.swing.*. //Atur Fillter jenis file dengan Handle fc fc = new JFileChooser().swing.BufferedWriter.MessageDigest. ". final String[] EXT2 = { ".JFrame.io. //Saat di awal aplikasi //Judul = Untitled this. } private boolean okToReplace() { . } JFileChooser fc.swing.io.filechooser. fc.java" }. boolean fileBaru.setAcceptAllFileFilterUsed(false).

JOptionPane. // selain kedua hal di atas.showConfirmDialog(this. } catch (IOException e) { msg("Gagal Simpan File : '" + file. for (int i = 0. } } private void SimpanFile() { PrintWriter pw = null.length.NOTES" ).getName()+" Sudah Ada\n"+ "Akan Ditimpa ?". "File "+file. tampilkan for (int i = 0.getName()). this.getName()+" .isDirectory()) return true. // Jika Extension dari file sesuai syarat.close(). ++i) tmp += "*" + s[i] + " ". } pw.getText()). fileBaru = false. } class jenisFile extends FileFilter { private String[] s. jenisFile(String[] sArg) { s = sArg. return tmp. try { pw = new PrintWriter(new BufferedWriter(new FileWriter(file))).setTitle(file. pw. i < s. } // Tentukan file apa yang akan ditampilkan public boolean accept(File fArg) { if (fArg. i < s. ++i) if (fArg. } class Enskripsimd5 { .YES_NO_OPTION)==0) .toLowerCase()) > 0) return true.indexOf(s[i].toLowerCase().getName(). } public String getDescription() { String tmp = "". return.print(isi1.return (JOptionPane.length. anggap false return false. "Peringatan".

md = MessageDigest. return convertToHex(md5hash). } halfbyte = data[i] & 0x0F. i++) { int halfbyte = (data[i] >>> 4) & 0x0F.awt.(int) geser.digest().EventQueue.length()). UnsupportedEncodingException { MessageDigest md.getBytes("iso-8859-1").append((char) ('a' + (halfbyte .getInstance("MD5"). } private String readFile(File file){ String result="". } }).getValue()))).setVisible(true). byte[] md5hash = new byte[32]. i < data. DataInputStream dis=new DataInputStream(bis). BufferedInputStream bis=new BufferedInputStream(fis). for (int i = 0.length.private String convertToHex(byte[] data) { StringBuffer buf = new StringBuffer().available()!=0){ . } while (two_halfs++ < 1). 0.append((char) ('0' + halfbyte)). int two_halfs = 0. do { if ((0 <= halfbyte) && (halfbyte <= 9)) { buf.toString(). } else { buf. try{ FileInputStream fis=new FileInputStream(file). } public String MD5(String text) throws NoSuchAlgorithmException. md. text. while(dis. } } public static void main(String args[]) { java.update(text.invokeLater(new Runnable() { public void run() { new ta_java(). } return buf. md5hash = md.

getPath().awt.add(fc)).showOpenDialog(jf.ActionEvent evt) { JFileChooser fc= new JFileChooser().ActionEvent evt) { if (fileBaru) simpan. } } catch(FileNotFoundException e){ } catch(IOException e){ } return result. if(ret==JFileChooser. isi1. text=readFile(file).NOTES"). JFrame jf= new JFrame().getSelectedFile().result +=dis.requestFocus(). if (!file.setText(text).awt.awt.ActionEvent evt) { if (fc.event. this.getSelectedFile(). isi1. int ret= fc.awt.readLine()+"\n". }  Coding Simpan Sebagai: private void simpan_sbgActionPerformed(java. else SimpanFile().event. nama_file. }  Masukkan coding untuk buka file: private void bukaActionPerformed(java.event. namafiletext=file.doClick(). } }  Kemudian coding untuk Simpan File: private void simpanActionPerformed(java.setText(namafiletext).APPROVE_OPTION){ file = fc. fileBaru = true.event. } }  Coding New File: private void baruActionPerformed(java.exists() || okToReplace()) SimpanFile().setText("").toString().APPROVE_OPTION) { File file=fc.showSaveDialog(this) == JFileChooser.setTitle("Untitled . .ActionEvent evt) { isi1.

} }  Coding Random1: private void random1ActionPerformed(java.event.length(). . randomKey = randomKey + (char) randomNumber. md5_2.class. Enskripsimd5 md5 = new Enskripsimd5(). pass2.event.MD5(isi1.log(Level. } catch (NoSuchAlgorithmException ex) { Logger.setEnabled(true).}  Coding Keluar: private void keluarActionPerformed(java.SEVERE. String randomKey = "".setEnabled(true). } catch (UnsupportedEncodingException ex) { Logger.getLogger(ta_java. for (int i = 0. password2. double randomNumber.setEnabled(true).setEnabled(true).setEnabled(true).awt.setEnabled(true).setEnabled(true).event.setEnabled(true). null.random() * 25 + 65.awt. saveas2.getLogger(ta_java.setEnabled(true). try { isi2. null). random2.SEVERE.setEnabled(true).log(Level. md5_2. i < isi1. saveas2.setEnabled(true).awt. i++) { randomNumber = Math.ActionEvent evt) { System. isi2.ActionEvent evt) { isi1.getText().getName()).setEnabled(true).exit(0). pass2.event. }  Coding MD5_1: private void md5_1ActionPerformed(java. isi2.setEnabled(true).awt. }  Coding Ubah: private void ubahActionPerformed(java.class.setText(md5.ActionEvent evt) { save2. password1. random2.ActionEvent evt) { save2.getName()).getText())). ex).setEnabled(true).setEnabled(true).

ActionEvent evt) { if (pass2.equals(pass1.event.ActionEvent evt) { if (fileBaru) { saveas2.getText()).length().getText())) { msg("password anda benar : " + pass1.event. double randomNumber. i++) { randomNumber = Math. }  Coding Password1: private void password1ActionPerformed(java. } isi1.event.ActionEvent evt) { String randomKey = "". } }  Coding Password2: private void password2ActionPerformed(java.random() * 25 + 65.exists() || okToReplace()) { SimpanFile(). isi1.APPROVE_OPTION) { file = fc.ActionEvent evt) { .getText().getText().} isi2.setText(randomKey).awt.event.doClick().getSelectedFile().awt. } }  Coding Saveas2: private void saveas2ActionPerformed(java. }  Coding Save2: private void save2ActionPerformed(java.ActionEvent evt) { if (fc. i < isi2. randomKey = randomKey + (char) randomNumber.setText(isi2. } else { msg("password anda salah : " + pass1.awt. if (!file.awt.event. for (int i = 0. } } }  Coding Random2: private void random2ActionPerformed(java.getText()).awt.showSaveDialog(this) == JFileChooser. } else { SimpanFile().getText()).setText(randomKey).

} else { msg("password anda salah : " + pass2. Bila anda ingin mengetahui Project saya.getText())) { msg("password anda benar : " + pass2. anda bisa menhubungi saya di WALL saya : AJI SUKMA SEJATI ATAU CALL ane di : 082331011658 SUMBER : PIKIRAN ANE BESARTA KAKAK KAKAK KELAS ANE : TERIMA KASIH .getText()). isi2.if (pass1.getText(). coba cari sendiri dulu Kalau.getText()).setText(isi1.getText()). } } Setelah itu coba di RUN. Jika ada coding yang masih error.equals(pass2.