BCRYPT LÀ GÌ

BCrypt là gì?

BCrypt là một thuật toán thù mã hóa mật khẩu đăng nhập được thiết kế theo phong cách bởi Niels Provos and David Mazières.

Bạn đang xem: Bcrypt là gì

BCrypt được Review là bảo mật thông tin và bình yên hơn so với MD5 với SHA bởi vì các lần triển khai băm này lại cho một cực hiếm khác nhau, câu hỏi này làm cho câu hỏi dò tìm kiếm password trsinh hoạt đề xuất nặng nề rộng.

Xem thêm: Code Võ Lâm Truyền Kỳ H5 - Web Game Võ Lâm Truyền Kỳ H5

Code ví dụ BCrypt

Ở trên đây mình thực hiện thỏng viện JBCrypt nhằm tiến hành băm cùng đối chiếu giá băm.

Các bạn cũng có thể tải về bốn viện trên đây

Hoặc import bằng maven:

org.mindrot jbcrypt 0.4Ví dụ triển khai băm một đoạn text:

String password = "danangmoment.com";String hash = BCrypt.hashpw(password, BCrypt.gensalt(12));System.out.println("BCrypt hash: " + hash);Trong đó BCrypt.gensalt khẳng định số vòng, số vòng dao động tự 4-30, số vòng càng lớn thì thời gian tiến hành băm càng thọ.

Kết quả:

BCrypt hash: $2a$12$7oh8QTspcMvrD8zBjWW4NePLXm2Xf.ffFfXqj5CbLIf.elGx9A9CeThực hiện chạy lại một lần tiếp nữa ta được một chuỗi khác:

BCrypt hash: $2a$12$Pmn0xKt4ZDtYAA6HypdWhuniNequ8ou2x7kG.9n.2Thw.Mza1RR.Clấy ví dụ như thực hiện chứng thực mật khẩu với một quãng mã băm (BCrypt hash)

String password = "danangmoment.com";boolean valuate = BCrypt.checkpw(password, "$2a$12$OFOICietLS3.qRtzIe6jE.vF.fmtL22DqIZ18WNMmQ.8nS7Frq5aO");System.out.println(valuate);Kết quả:

true

Demo mã hóa với xác nhận mật khẩu:

package danangmoment.com.bcrypttest.demo;import java.awt.Color;import java.awt.EventQueue;import java.awt.event.ActionEvent;import java.awt.sự kiện.ActionListener;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.border.EmptyBorder;import javax.swing.border.TitledBorder;import org.mindrot.jbcrypt.BCrypt;public class MainApp extends JFrame private static final long serialVersionUID = 1L; private JPanel contentPane; private JPanel panelCalculator; private JPanel panelTester; private JLabel lblEnterPasswordTo; private JTextField textFieldPassToHash; private JLabel lblRound; private JComboBox comboBoxRound; private JButton btnCalculateHash; private JTextField textFieldHashResult; private JLabel lblPasswordToEvaluate; private JTextField textFieldPassToEvaluate; private JTextField textFieldBcryptHashToEvaluate; private JLabel lblBcryptHashTo; private JButton btnTest; private JTextField textFieldEvaluteResult; /** * Launch the application. */ public static void main(String<> args) EventQueue.invokeLater(new Runnable() public void run() try MainApp frame = new MainApp(); frame.setVisible(true); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(frame); catch (Exception e) e.printStackTrace(); ); /** * Create the frame. */ public MainApp() setTitle("BCrypt Demo - danangmoment.com"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 579, 399); this.contentPane = new JPanel(); this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(this.contentPane); this.contentPane.setLayout(null); this.panelCalculator = new JPanel(); this.panelCalculator.setBorder(new TitledBorder(null, "BCrypt Calculator", TitledBorder.LEADING, TitledBorder.TOP, null, null)); this.panelCalculator.setBounds(12, 13, 543, 142); this.contentPane.add(this.panelCalculator); this.panelCalculator.setLayout(null); this.lblEnterPasswordTo = new JLabel("Enter password to Hash: "); this.lblEnterPasswordTo.setBounds(12, 28, 152, 16); this.panelCalculator.add(this.lblEnterPasswordTo); this.textFieldPassToHash = new JTextField(); this.textFieldPassToHash.setBounds(153, 25, 372, 22); this.panelCalculator.add(this.textFieldPassToHash); this.textFieldPassToHash.setColumns(10); this.lblRound = new JLabel("Maximum number of rounds which is tolerable:"); this.lblRound.setBounds(12, 61, 278, 16); this.panelCalculator.add(this.lblRound); this.comboBoxRound = new JComboBox(); this.comboBoxRound.setModel(new DefaultComboBoxModel(new String<> "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15")); this.comboBoxRound.setBounds(353, 57, 172, 22); this.panelCalculator.add(this.comboBoxRound); this.btnCalculateHash = new JButton("Calculate"); this.btnCalculateHash.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String password = textFieldPassToHash.getText(); if (password != null &và !password.isEmpty()) int round = Integer.parseInt(comboBoxRound.getSelectedItem().toString()); String hash = BCrypt.hashpw(password, BCrypt.gensalt(round)); textFieldHashResult.setText(hash); ); this.btnCalculateHash.setBounds(12, 90, 95, 25); this.panelCalculator.add(this.btnCalculateHash); this.textFieldHashResult = new JTextField(); this.textFieldHashResult.setEditable(false); this.textFieldHashResult.setBounds(153, 90, 372, 22); this.panelCalculator.add(this.textFieldHashResult); this.textFieldHashResult.setColumns(10); this.panelTester = new JPanel(); this.panelTester.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "BCrypt Tester", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); this.panelTester.setBounds(12, 179, 543, 175); this.contentPane.add(this.panelTester); this.panelTester.setLayout(null); this.lblPasswordToEvaluate = new JLabel("Password to lớn evaluate:"); this.lblPasswordToEvaluate.setBounds(12, 26, 134, 16); this.panelTester.add(this.lblPasswordToEvaluate); this.textFieldPassToEvaluate = new JTextField(); this.textFieldPassToEvaluate.setColumns(10); this.textFieldPassToEvaluate.setBounds(154, 23, 380, 22); this.panelTester.add(this.textFieldPassToEvaluate); this.textFieldBcryptHashToEvaluate = new JTextField(); this.textFieldBcryptHashToEvaluate.setColumns(10); this.textFieldBcryptHashToEvaluate.setBounds(154, 74, 380, 22); this.panelTester.add(this.textFieldBcryptHashToEvaluate); this.lblBcryptHashTo = new JLabel("BCrypt hash to lớn evaluate:"); this.lblBcryptHashTo.setBounds(12, 77, 134, 16); this.panelTester.add(this.lblBcryptHashTo); this.btnTest = new JButton("Calculate"); this.btnTest.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String password = textFieldPassToEvaluate.getText(); String hash = textFieldBcryptHashToEvaluate.getText(); boolean match = BCrypt.checkpw(password, hash); if (match) textFieldEvaluteResult.setText("Password và hash match"); else textFieldEvaluteResult.setText("Password and hash vì chưng NOT match"); ); this.btnTest.setBounds(12, 123, 95, 25); this.panelTester.add(this.btnTest); this.textFieldEvaluteResult = new JTextField(); this.textFieldEvaluteResult.setEditable(false); this.textFieldEvaluteResult.setColumns(10); this.textFieldEvaluteResult.setBounds(153, 123, 372, 22); this.panelTester.add(this.textFieldEvaluteResult);
*

Leave a Reply

Your email address will not be published. Required fields are marked *