I'm currently using jasypt as my encryption tool, the problem is once a word has been encrypted, it produces '/', i want to avoid slashes in my encryptions. the reason for that is i'm using it in my url.
so for example jasypt produces this encrypted text:
String encryptedText = "/O0sJjPUFgRGfND1TpHrkbyCalgY/rSpE8nhJ/wYjYY=";
I will be appending this in my link..
example of that is:
String.format("%s%s", "youtube.com/videos/", encryptedText);
this will redirect me to another link, so instead of going to videos section, it will go to /O0sJjPUFgRGfND1TpHrkbyCalgY
here's my code:
public class EncryptionUtil {
public static final String ENCRYPTION_KEY = "test-encryption";
private static final String EMPTY_KEY_OR_TEXT = "Decryption key and text must not be empty.";
public static String decrypt(final String encryptedText) {
if (StringUtils.isAnyBlank(encryptedText)) {
throw new ApiErrorException(EMPTY_KEY_OR_TEXT);
}
try {
final char[] keyCharArray = ENCRYPTION_KEY.toCharArray();
final BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPasswordCharArray(keyCharArray);
return textEncryptor.decrypt(encryptedText);
} catch (EncryptionOperationNotPossibleException e) {
throw new ApiErrorException(e.getMessage());
}
}
public static String encrypt(final String plaintext) {
if (StringUtils.isAnyBlank(plaintext)) {
throw new ApiErrorException(EMPTY_KEY_OR_TEXT);
}
final char[] keyCharArray = ENCRYPTION_KEY.toCharArray();
final BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPasswordCharArray(keyCharArray);
return textEncryptor.encrypt(plaintext);
}
}
Here's my spring controller:
@GetMapping("/profile/client-users/{userId}")
public ModelAndView getAccountAccess(
@PathVariable String userId, ModelMap modelMap) {
userId = EncryptionUtil.decrypt(userId);
}