Information Security
Information Security
NECCESSARY LIBARIES
• javax.crypto.SecretKey: To store the generated secret key
used for encryption.
• java.util.Base64: Used to encode and decode data in
Base64.
• javax.swing.*: For creating the graphical user
interface (GUI)
• javax.swing.*: For creating the graphical user
interface (GUI)
• class Firewall { The Firewall class is a security feature that
checks if a device’s IP address matches a pre-
private static final String ALLOWED_IP = "192.168.1.1"; set allowed IP address ("192.168.1.1"). If the
provided IP matches the allowed one, the
public static boolean isIPAllowed(String ip) { isIPAllowed() method returns true, granting
access; otherwise, it returns false, blocking
return ALLOWED_IP.equals(ip); access. It acts as a basic check to restrict
}} access based on the device's IP address.
GenerateKey() Static Block
private static SecretKey generateKey() throws Exception { static {
try {
KeyGenerator keyGen = KeyGenerator.getInstance("AES"); secretKey = generateKey();
System.out.println("SecretKey changes everytime a person logs in
keyGen.init(128); // 128-bit AES encryption : " + secretKey);
} catch (Exception e) {
return keyGen.generateKey(); e.printStackTrace();
}
} }
GenerateKey() Static Block
What it does: This method creates a new AES key. • What it does: This block of code runs once when the class is loaded.
It generates a new AES key and stores it in the secretKey variable.
• KeyGenerator.getInstance("AES"): This gets the AES
encryption algorithm's key generator. • Why it’s important: The encryption key is generated dynamically,
which means it’s not fixed and changes each time the program runs,
• keyGen.init(128): This specifies the key size, which is 128 making it more secure.
bits in this case. AES supports key sizes of 128.
• First, the username and password entered by the user are encrypted
using the Encryption.encrypt() method.