Kaskus

Tech

albidwiAvatar border
TS
albidwi
ask enkripsi dan dekripsi
gan bantuin ane dong jadi ane lagi buat aplikasi enkrip dan dekrip nah ane mau nanya kalo key di dekrip salah ada pemberitahuan salah kalo punya ane kalo key salah bisa di decrypt tapi isi filenya kosong nah supaya ada pemberitahuan wrong key gan

nih source code ane
void enkrip1(){

try{

FileInputStream file = new FileInputStream(txtpt.getText());
FileOutputStream outStream = new FileOutputStream("Encrypt.txt.enc");
String K = txtpassword.getText();
SecretKeySpec key = new SecretKeySpec(konversiKeByte(K), "AES");
Cipher enc = Cipher.getInstance("AES");
enc.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(outStream, enc);
byte[] buf = new byte[1024];
int read;
while((read=file.read(buf))!=-1){
cos.write(buf,0,read);
}
file.close();
outStream.flush();
cos.close();
JOptionPane.showMessageDialog(null, "The file encrypted Successfully");
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}

}

void dekrip(){
try{
FileInputStream file = new FileInputStream(txtpt.getText());
FileOutputStream outStream = new FileOutputStream("Decrypt.txt");
String K = txtpassword.getText();
SecretKeySpec key = new SecretKeySpec(konversiKeByte(K), "AES");
Cipher enc = Cipher.getInstance("AES");
enc.init(Cipher.DECRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(outStream, enc);
byte[] buf = new byte[1024];
int read;
while((read=file.read(buf))!=-1){
cos.write(buf,0,read);
}
file.close();
outStream.flush();
cos.close();
JOptionPane.showMessageDialog(null, "The was decrypted successfully");
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
0
739
4
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Programmer Forum
Programmer Forum
KASKUS Official
20.2KThread5KAnggota
Urutkan
Terlama
GuestAvatar border
Komentar yang asik ya
Ikuti KASKUS di
© 2026 KASKUS, PT Darta Media Indonesia. All rights reserved.