Selasa, 23 Mei 2023

Engkripsi Kalimat Dengan MD5 Dan SHA3-512

 

package sonienkripsi;
 
import java.math.BigInteger;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
import javax.swing.JOptionPane;
 
/**
 *
 * @author Soni Hendarkanto on Apache NetBeans IDE 16 with Linux Mint 21.1
 * "VERA" Cinnamon Desktop Edition
 * My github: https://github.com/Soni-Hendar-Kip/SoniEnkripsi
 */
public class NoxEnkripsiMD5_SHA3 extends javax.swing.JFrame {
 
    String NoxPassword, NoxMD5, NoxSHA3_512;
 
    /**
     * Creates new form NoxEnkrip
     */
    public NoxEnkripsiMD5_SHA3() {
        initComponents();
    }
 
    private String encryptPasswordMD5() {
        NoxPassword = TextAsli.getText();
        String encPass = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(NoxPassword.getBytes(), 0, NoxPassword.length());
            encPass = new BigInteger(1, digest.digest()).toString(16);
            NoxMD5 = encPass.toUpperCase();
            TextMD5.setText(NoxMD5);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encPass;
    }
 
    private String encryptPasswordSHA3_512() {
        NoxPassword = TextAsli.getText();
        String encPass = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA3-512");
            digest.update(NoxPassword.getBytes(), 0, NoxPassword.length());
            encPass = new BigInteger(1, digest.digest()).toString(16);
            NoxSHA3_512 = encPass.toUpperCase();
            TextSHA3_512.setText(NoxSHA3_512);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encPass;
    }
 
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */                   
 
    private void ButProses_ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        if (TextAsli.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Teks asli masih kosong..");
            TextAsli.requestFocus();
        } 
        else {
            encryptPasswordSHA3_512();
            encryptPasswordMD5();
            //txtSHA1MD5.setText(NoxSHA3_512 + NoxMD5);
        }
    }                                          
 
    private void ButReadme_ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        new Readme().setVisible(true);
    }                                          
 
    private void ButReset_ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        TextAsli.setText("");
        TextMD5.setText("");
        TextSHA3_512.setText("");
    }                                         
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NoxEnkripsiMD5_SHA3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NoxEnkripsiMD5_SHA3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NoxEnkripsiMD5_SHA3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NoxEnkripsiMD5_SHA3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NoxEnkripsiMD5_SHA3().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton ButProses_;
    private javax.swing.JButton ButReadme_;
    private javax.swing.JButton ButReset_;
    private javax.swing.JTextArea TextAsli;
    private javax.swing.JTextArea TextMD5;
    private javax.swing.JTextArea TextSHA3_512;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    // End of variables declaration                   
} 
 

 

Tidak ada komentar:

Posting Komentar