def decrypt(encrypted)
      fail ArgumentError, 'No cipher text supplied.' if encrypted.nil? || encrypted.empty?

      matches = CIPHER_PATTERN.match(encrypted)

      fail ArgumentError, 'Cipher text has an unsupported format.' if matches.nil?

      cipher = self.class.cipher
      cipher.decrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = Base64.decode64(matches[1])
      decrypted = cipher.update(Base64.decode64(matches[2]))

      decrypted << cipher.final
    end
def decrypt(encrypted)
      fail ArgumentError, 'No cipher text supplied.' if encrypted.nil? || encrypted.empty?

      matches = CIPHER_PATTERN.match(encrypted)

      fail ArgumentError, 'Cipher text has an unsupported format.' if matches.nil?

      cipher = self.class.cipher
      cipher.decrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = Base64.decode64(matches[1])
      decrypted = cipher.update(Base64.decode64(matches[2]))

      decrypted << cipher.final
    end
This method expects a base64 encoded cipher text and decrypts it.

 @param encrypted [String] Cipher text.

 @return [String] Plain text.