java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.AesGcmKeyCipher

@Component public class AesGcmKeyCipher extends Object
Encrypts and decrypts the private half of signing keys with AES-256-GCM (Spring Security's Encryptors.stronger). Every encryption uses a fresh random initialisation vector, so encrypting the same text twice gives different results.
  • Field Details

    • encryptor

      private final org.springframework.security.crypto.encrypt.BytesEncryptor encryptor
      The encryptor derived from the passphrase and the salt.
  • Constructor Details

    • AesGcmKeyCipher

      public AesGcmKeyCipher(KeyEncryptionProperties properties)
      Derives the encryption key.
      Parameters:
      properties - passphrase and salt.
  • Method Details

    • encrypt

      public String encrypt(String plain)
      Encrypts a text.
      Parameters:
      plain - the text.
      Returns:
      the encrypted text, Base64 encoded.
    • decrypt

      public String decrypt(String encrypted)
      Decrypts a text produced by encrypt(String).
      Parameters:
      encrypted - the encrypted text.
      Returns:
      the original text.
      Throws:
      IllegalStateException - if the text was not encrypted with the same passphrase and salt, or was altered.