Sobes.tech
Junior — Middle

What encryption methods and data protection techniques are you familiar with?

sobes.tech AI

Answer from AI

In Java, the following methods and techniques are often used for encryption and data protection:

  • Symmetric encryption (e.g., AES) — one key for encryption and decryption.
  • Asymmetric encryption (e.g., RSA) — a pair of keys: public and private.
  • Hashing (e.g., SHA-256) — one-way transformation of data for integrity verification.
  • Digital signatures — to confirm authenticity and data integrity.
  • Using Java Cryptography Architecture (JCA) and libraries such as Bouncy Castle.

Example of using AES for string encryption:

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class EncryptionExample {
    public static void main(String[] args) throws Exception {
        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        keyGen.init(128);
        SecretKey secretKey = keyGen.generateKey();

        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);

        String text = "Hello, World!";
        byte[] encrypted = cipher.doFinal(text.getBytes());

        System.out.println("Encrypted data: " + java.util.Base64.getEncoder().encodeToString(encrypted));
    }
}
What encryption methods and data protection… - sobes.tech