"I want to safely manage the passwords I use for various services."
"I want to create a tool that is useful for practicing Java."
For those who have such concerns,Building your own password management toolis.
This tool allows you to:Register, search, and encrypt passwordsThrough features such as
JavaFile operations, encryption, class design, and repetitive processingYou can learn in a well-balanced way.
In this article,A secure password management app that anyone can easily implementWe will explain how to create this in an easy-to-understand manner, with code included.
- What is a password manager?
- Understand the structure of the tool you want to create
- Creating the Credential Class
- Create the encryption class AESUtil
- Main process: PasswordManager class
- Security Considerations
- Application ideas: GUI and export functions
- Completed code summary
- Summary: Learn secure management with Java
What is a password manager?
Learn practical security tools with Java
Conclusion: You can easily experience the ability to securely store and manage passwords using Java.
We use a lot of passwords, including for social media, shopping, and work accounts.
It is very dangerous to manage them on paper or in a notebook.
That's where a password management tool comes in handy.
With Java,Your own simple toolBy creating this, you can also learn about file storage and encryption at the same time.
Understand the structure of the tool you want to create
Simple design with a minimum of three functions
Conclusion: You can create a practical management tool with just these three features:
- Register password (save service name + ID + PW)
- Search for registered information
- Save and load to file (with encryption)
Structure image:
PasswordManager.java ├─ List Data retention ├─ AESUtil.java Encryption/decryption processing └─ password.dat Saved file
Creating the Credential Class
Data class with registration information (service name, ID, password)
public class Credential { private String service; private String user; private String password; public Credential(String service, String user, String password) { this.service = service; this.user = user; this.password = password; } public String getService() { return service; } public String getUser() { return user; } public String getPassword() { return password; } @Override public String toString() { return "Service: " + service + ", User ID: " + user + ", Password: " + password; } }
Create the encryption class AESUtil
Make your passwords safe with Java's AES method
import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.util.Base64; public class AESUtil { private static final String KEY = "1234567890123456"; // 16 characters public static String encrypt(String data) throws Exception { SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), } public static String decrypt(String encrypted) throws Exception { SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decoded = Base64.getDecoder().decode(encrypted); byte[] decrypted = cipher.doFinal(decoded); return new String(decrypted); } }
Main process: PasswordManager class
Implemented the function to register and search from command line
import java.io.*; import java.util.*; public class PasswordManager { private static final String FILE = "password.dat"; private static List credentials = new ArrayList<>(); public static void main(String[] args) throws Exception { load(); Scanner scanner = new Scanner(System.in); while (true) { System.out.println("\n1. Register | 2. Search | 0. Finish"); System.out.print("Please Select: "); String input = scanner.nextLine(); if (input.equals("1")) { System.out.print("Service Name: "); String service = scanner.nextLine(); System.out.print("User ID: "); String user = scanner.nextLine(); System.out.print("Password: "); String password = scanner.nextLine(); credentials.add(new Credential(service, user, password)); save(); System.out.println("Successfully registered"); } else if (input.equals("2")) { System.out.print("Enter Service Name: "); String keyword = scanner.nextLine(); for (Credential c : credentials) { if (c.getService().equalsIgnoreCase(keyword)) { System.out.println(c); } } } else if (input.equals("0")) { break; } else { System.out.println("Invalid input."); } } } private static void save() Exception { BufferedWriter writer = new BufferedWriter(new FileWriter(FILE)); for (Credential c : credentials) { String encrypted = AESUtil.encrypt(c.getService() + "," + c.getUser() + "," + c.getPassword()); writer.write(encrypted); writer.newLine(); } writer.close(); } private static void load() throws Exception { File f = new File(FILE); if (!f.exists()) return; BufferedReader reader = new BufferedReader(new FileReader(FILE)); String line; while ((line = reader.readLine()) != null) { String decrypted = AESUtil.decrypt(line); String[] parts = decrypted.split(",", 3); credentials.add(new Credential(parts[0], parts[1], parts[2])); } reader.close(); } }
Security Considerations
Basic precautions for safe handling
- Don’t embed the encryption key in the app, but use it as an environment variable
- Restrict access to the file (if you are using Windows, right-click and select Properties).
- Add automatic logout and PIN code for added security
Application ideas: GUI and export functions
How can we make it a more useful tool?
- Create a GUI with Swing for visual ease of use
- Export to CSV file for external integration
- Enhanced protection with master password
Completed code summary
- Credential.java: Model class for registration information
- AESUtil.java: Encryption/decryption management class
- PasswordManager.java: The tool itself
- password.dat: Saved file (encrypted)
Summary: Learn secure management with Java
In this article,A password management tool using JavaWe introduced the following.
What I learned:
- File I/O mechanism
- Basics of AES Encryption with Java
- Simple tool design flow
Based on this tool,A secure password management appPlease develop it into something more!