Class KmsTemplate

java.lang.Object
com.google.cloud.spring.kms.KmsTemplate
All Implemented Interfaces:
KmsOperations

public class KmsTemplate extends Object implements KmsOperations
Offers convenience methods for performing common operations on KMS including encrypting and decrypting text.
  • Constructor Details

    • KmsTemplate

      public KmsTemplate(com.google.cloud.kms.v1.KeyManagementServiceClient keyManagementServiceClient, GcpProjectIdProvider projectIdProvider)
  • Method Details

    • encryptText

      public byte[] encryptText(String cryptoKey, String text)
      Description copied from interface: KmsOperations
      Encrypt the text using the specified KMS resource string cryptoKey.

      An encryption request will be issued using GCP KMS.

      Specified by:
      encryptText in interface KmsOperations
      Parameters:
      cryptoKey - The KMS resource string
      text - UTF-8 encoded text to encrypt
      Returns:
      The encrypted bytes
    • encryptBytes

      public byte[] encryptBytes(String cryptoKey, byte[] bytes)
      Description copied from interface: KmsOperations
      Encrypt the bytes using the specified KMS resource string cryptoKey.

      An encryption request will be issued using GCP KMS.

      Specified by:
      encryptBytes in interface KmsOperations
      Parameters:
      cryptoKey - The KMS resource string
      bytes - The bytes to encrypt
      Returns:
      The encrypted bytes
    • decryptText

      public String decryptText(String cryptoKey, byte[] cipherText)
      Description copied from interface: KmsOperations
      Decrypt the text using the specified KMS resource string cryptoKey

      A decryption request will be issued using GCP KMS.

      Specified by:
      decryptText in interface KmsOperations
      Parameters:
      cryptoKey - The KMS resource string
      cipherText - The encrypted bytes
      Returns:
      The decrypted bytes UTF-8 encoded
    • decryptBytes

      public byte[] decryptBytes(String cryptoKey, byte[] cipherText)
      Description copied from interface: KmsOperations
      Decrypt the text using the specified KMS resource string cryptoKey

      A decryption request will be issued using GCP KMS.

      Specified by:
      decryptBytes in interface KmsOperations
      Parameters:
      cryptoKey - The KMS resource string
      cipherText - The encrypted bytes
      Returns:
      The decrypted bytes