-1
我有一个函数加密和解密密码的加密和解密。当我将密码发送到数据库时,我会对其进行加密并发送,但要使用它,我先将其解密并将其发送到那里。 但我不想让任何人使用System.out.println在控制台上打印密码。 它应该以某种方式锁定。 我们可以为此做些什么?我已经用java编码并使用Key编写我的代码。 我的代码是如果我有密码加密和解密功能,有没有什么办法可以在我们的java代码中打印解密后的密码?
String text = "Hello World";
String key = "Bar12345Bar12345"; // 128 bit key
// Create key and cipher
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
// encrypt the text
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
byte[] encrypted = cipher.doFinal(text.getBytes());
System.err.println(new String(encrypted));
// decrypt the text
cipher.init(Cipher.DECRYPT_MODE, aesKey); String decrypted = new String(cipher.doFinal(encrypted));
System.err.println(decrypted);
第一件事不使用字符串的密码。使用char []。 – Amit1011
从不安全的选项加密和解密密码。你应该改为散列函数。 –
@RamanSahasi不错的主意,但只有当你使用密码*验证*用户输入的内容才有效。如果您使用密码对其他服务进行身份验证,则需要将其重建为原始密码。 –