How to use the tink.core.cleartext_keyset_handle.CleartextKeysetHandle function in tink

To help you get started, we’ve selected a few tink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / tink / tools / testing / python / aead_cli.py View on Github external
def read_keyset(keyset_filename):
  """Load a keyset from a file.

  Args:
    keyset_filename: A path to a keyset file

  Returns:
    A KeysetHandle of the file's keyset
  Raises:
    TinkError: if the file is not valid
    IOError: if the file does not exist
  """
  with open(keyset_filename, 'rb') as keyset_file:
    text = keyset_file.read()
    keyset = cleartext_keyset_handle.CleartextKeysetHandle(
        tink.BinaryKeysetReader(text).read())
  return keyset
github google / tink / examples / file_mac / python / file_mac_cleartext.py View on Github external
expected_code_hex = None
    logging.info('Using keyset from file %s to verify file %s', keyset_filename,
                 data_filename)

  # Initialise Tink.
  try:
    tink.tink_config.register()
  except tink.TinkError as e:
    logging.error('Error initialising Tink: %s', e)
    return 1

  # Read the keyset.
  with open(keyset_filename, 'rb') as keyset_file:
    try:
      text = keyset_file.read()
      keyset = cleartext_keyset_handle.CleartextKeysetHandle(
          tink.JsonKeysetReader(text).read())
    except tink.TinkError as e:
      logging.error('Error reading key: %s', e)
      return 1

  # Get the primitive.
  try:
    cipher = keyset.primitive(tink.Mac)
  except tink.TinkError as e:
    logging.error('Error creating primitive: %s', e)
    return 1

  # Compute the MAC.
  with open(data_filename, 'rb') as data_file:
    data = data_file.read()