import re


def strip_headers(pem_text):
    """
    Strips the headers off a a FinCrypt key or message.

    :param pem_text: Text of key or message (string)
    :return: Tuple (header (ie. 'BEGIN FINCRYPT MESSAGE'), base64 (string))
    """

    match = re.match(
        r'(?:-+ (BEGIN FINCRYPT (?:PUBLIC |PRIVATE )?(?:KEY|MESSAGE)) -+\n)([a-zA-Z0-9\n\-_=]+[^\n])'
        r'(?:\n-+ END FINCRYPT (?:PUBLIC |PRIVATE )?(?:KEY|MESSAGE) -+)', pem_text)
    if match is None:
        return None, None
    return match[1], match[2]