Here is a very short example of using true encryption. It's 128 bit AES, which is farily secure - certainly not readable by any stretch of the imagination.
It generates a random key, so it would be different on each run. You would need to share they key between the two programs exchanging data somehow.
private static final String ENCRYPTION_ALGORITHM = "AES/ECB/PKCS5Padding";
private static final SecureRandom RANDOM = new SecureRandom();
public static void main(String[] args) throws UnsupportedEncodingException, GeneralSecurityException {
final KeyGenerator keyGen = KeyGenerator.getInstance(ENCRYPTION_ALGORITHM.substring(0, ENCRYPTION_ALGORITHM.indexOf('/')));
keyGen.init(128, RANDOM);
final SecretKey key = keyGen.generateKey();
final String s = "My topsecret string";
System.out.println(s);
final Cipher encryption = getCipher(key, Cipher.ENCRYPT_MODE);
final String enc = DatatypeConverter.printBase64Binary(encryption.doFinal(s.getBytes("UTF-8")));
System.out.println(enc);
final Cipher decryption = getCipher(key, Cipher.DECRYPT_MODE);
final String dec = new String(decryption.doFinal(DatatypeConverter.parseBase64Binary(enc)), "UTF-8");
System.out.println(dec);
}
private static Cipher getCipher(final Key key, final int mode) throws GeneralSecurityException {
final Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(mode, key, RANDOM);
return cipher;
}
Output:
My topsecret string
ip4La5KUBJGTTYenoE920V5w0VBHwALv4fp3qyLTY9o=
My topsecret string