EKRIP:
long start=System.currentTimeMillis(); String keyText=txtpassword.getText().toString(); String txtsrc=txtnama.getText().toString();//SRC String txtdst=txtPath.getText().toString();//DST String fileName=txtsrc; cetak("Baca File ",fileName); cetak("Baca Posisi Encript ",txtdst); byte[]key=getByte2(keyText); Path path = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { path = Paths.get(fileName); } try { byte[] data = Files.readAllBytes(path); byte []ciper= encrypt(data, key); String NF=txtdst; saveByte(ciper,NF); sukses("Enkrip Berhasil","Path Simpan di:"+txtdst); } catch (IOException ex) { //Logger.getLogger(RC6.class.getName()).log(Level.SEVERE, null, ex); } long end=System.currentTimeMillis(); String selisih=((end - start) / 1000.0) + " Milidetik"; txtTime.setText(selisih);
SAVE:
byte[] key = getByte2(keyText); Path path = null; path = Paths.get(TEMP);//txtsrc // try { byte[] data = new byte[0]; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { try { data = Files.readAllBytes(path); cetak("Baca Save0",data.toString()); } catch (IOException ex) { ex.printStackTrace(); cetak("Baca Save1","ERRS1:"+ex.toString()); } } byte[] ciper = decrypt(data, key); try { cetak("Baca Save2","MAU SAVE KE :"+TEMP); saveByte2(ciper, TEMP,namafile,ext);//txtdst } catch (IOException ex) { ex.printStackTrace(); cetak("Baca Save3","ERRS2:"+ex.toString()); }
private void saveByte2(byte[] dataDecrypt,String NF,String namafile,String ext) throws IOException { Path path = Paths.get(NF); Files.write(path, dataDecrypt); //creates, overwrites String NF2=NF.replaceAll("xxx",ext); NF2=NF2.replaceAll(".DT",namafile); File currentFile = new File(NF); File newFile = new File(NF2); if (rename(currentFile, newFile)) { //Success cetak("Baca Rename", "Success Rename "+NF+" TO "+NF2); cetak("Baca Hasil","File Berhasil di dekripsi ! lihat di : " + NF2); sukses("Dekrip Sukses !","Cek Di:"+NF2); } else { //Fail cetak("Baca Rename", "Fail Rename "+NF+" TO "+NF2); cetak("Baca Hasil","File Berhasil di dekripsi ! lihat di : " + NF); sukses("Dekrip Gagal !","Cek Di:"+NF); } byte []getByte(String plainText){ byte[] output = plainText.getBytes(StandardCharsets.UTF_8); System.out.println("Text : " + plainText); String base64encoded = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { base64encoded = Base64.getEncoder().encodeToString(output); } System.out.println("Text [Base64] : " + base64encoded); return output; } String setString(byte[]output){ String base64encoded = Base64.getEncoder().encodeToString(output); return base64encoded; } byte []getByte2(String plainText){ byte[] bytes = plainText.getBytes(StandardCharsets.UTF_8); return bytes; } String setString2(byte[]output){ String s = new String(output, StandardCharsets.UTF_8); return s; }
Tidak ada komentar:
Posting Komentar