If your goal is not encryption but simply to hide the text in a way that deters casual observation (especially in something like a 2D barcode), you might consider Base64 encoding. It’s quick and easy, though it’s not true encryption. It simply makes the text appear garbled and obfuscated.
Here’s an example using Base64 encoding in java encryption:
import java.util.Base64;
public class Base64Example {
public static String encrypt(String data) {
return Base64.getEncoder().encodeToString(data.getBytes());
}
public static String decrypt(String encryptedData) {
return new String(Base64.getDecoder().decode(encryptedData));
}
public static void main(String[] args) {
String original = "Hello, World!";
String encrypted = encrypt(original);
String decrypted = decrypt(encrypted);
System.out.println("Original: " + original);
System.out.println("Encrypted: " + encrypted);
System.out.println("Decrypted: " + decrypted);
}
}
Why use Base64 encoding in java encryption?
- Fastest method for hiding text.
- Easy to decode, so authorized companies can retrieve the data.
- Not encryption, but simply an encoding method that makes text unreadable in scans.