Simple encryption in java-no key/password

I know its overkill but i would use jasypt library since its realy easy to use. All you need is random seed to encrypt or decrpyt.

Here is the source code for encrypting data:

String seed = "ipNumber";
String myIpValue = "192.168.0.1";

StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(seed);
String encrypted= encryptor.encrypt(myIpValue);

And for data decryption:

StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(seed);

String decrypted = encryptor.decrypt(encrypted);

Or you could just encode or decode your string to base64 example is show here: Base64 Java encode and decode a string


Almost the same as higuaro solutions but with a lot of fixes to make it work, the following code tested and working since higuaro not working well like characters went into numbers and when you reverse its get single number and damage everything:

public String caesarCipherEncrypt(String plain) {
   String b64encoded = Base64.getEncoder().encodeToString(plain.getBytes());

   // Reverse the string
   String reverse = new StringBuffer(b64encoded).reverse().toString();

   StringBuilder tmp = new StringBuilder();
   final int OFFSET = 4;
   for (int i = 0; i < reverse.length(); i++) {
      tmp.append((char)(reverse.charAt(i) + OFFSET));
   }
   return tmp.toString();
}

To de-crypt procede backwards:

public String caesarCipherDecrypte(String secret) {
   StringBuilder tmp = new StringBuilder();
   final int OFFSET = 4;
   for (int i = 0; i < secret.length(); i++) {
      tmp.append((char)(secret.charAt(i) - OFFSET));
   }

   String reversed = new StringBuffer(tmp.toString()).reverse().toString();
   return new String(Base64.getDecoder().decode(reversed));
}

I hope its helpful.