Deterministic TextEncryptor

1 day ago 1
ARTICLE AD BOX

I want this encryptor to return the same value for the same input. But that's not what happens.

import com.example.em_card_service.data.properties.EncryptionProperties; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.crypto.encrypt.Encryptors; import org.springframework.security.crypto.encrypt.TextEncryptor; import java.util.List; @Configuration @RequiredArgsConstructor public class SecurityConfig { private final EncryptionProperties encryptionProperties; // more beans @Bean public TextEncryptor textEncryptor() { return Encryptors.text(encryptionProperties.getPassword(), encryptionProperties.getSalt()); } }

I absolutely don't want to get bogged down in this encryption stuff. I want some magic API with encrypt()/decrypt() methods. I'm okay with providing that utility some hex strings ("salts", "passwords", whatever).

After going back and forth with Claude, it ended up saying: "The fix is to use javax.crypto directly". Not on my agenda.

How do I deterministically encrypt strings across multiple server runs by high-level means only (no Cipher)?

Spring Boot 4.

Read Entire Article