Class KmsTextEncryptor

  • All Implemented Interfaces:
    org.springframework.security.crypto.encrypt.TextEncryptor

    public class KmsTextEncryptor
    extends Object
    implements org.springframework.security.crypto.encrypt.TextEncryptor
    This TextEncryptor uses AWS KMS (Key Management Service) to encrypt / decrypt strings. Encoded cipher strings are represented in Base64 format, to have a nicer string representation (only alpha-numeric chars), that can be easily used as values in property files.
    • Constructor Detail

      • KmsTextEncryptor

        public KmsTextEncryptor​(com.amazonaws.services.kms.AWSKMS kms,
                                String kmsKeyId)
        Parameters:
        kms - The AWS KMS client
        kmsKeyId - The ID or full ARN of the KMS key, e.g. arn:aws:kms:eu-west-1:089972051332:key/9d9fca31-54c5-4de5-ba4f-128dfb9a5031. Must not be blank, if you you want to encrypt text.
    • Method Detail

      • encrypt

        public String encrypt​(String text)
        Specified by:
        encrypt in interface org.springframework.security.crypto.encrypt.TextEncryptor
      • decrypt

        public String decrypt​(String encryptedText)
        Specified by:
        decrypt in interface org.springframework.security.crypto.encrypt.TextEncryptor