def encrypt_payload(secret_key, payload):
    'Return a encrypted payload given a key and dictionary of data.'
    try:
        from nacl.secret import SecretBox
        from nacl.encoding import Base64Encoder
    except (ImportError, OSError):
        pytest.skip('libnacl/libsodium is not installed')
        return
    import json
    keylen = SecretBox.KEY_SIZE
    prepped_key = secret_key.encode('utf-8')
    prepped_key = prepped_key[:keylen]
    prepped_key = prepped_key.ljust(keylen, b'\x00')
    payload = json.dumps(payload).encode('utf-8')
    return SecretBox(prepped_key).encrypt(payload, encoder=Base64Encoder).decode('utf-8')
Return a encrypted payload given a key and dictionary of data.
def encrypt_payload(secret_key, payload):
    
    try:
        from nacl.secret import SecretBox
        from nacl.encoding import Base64Encoder
    except (ImportError, OSError):
        pytest.skip('libnacl/libsodium is not installed')
        return
    import json
    keylen = SecretBox.KEY_SIZE
    prepped_key = secret_key.encode('utf-8')
    prepped_key = prepped_key[:keylen]
    prepped_key = prepped_key.ljust(keylen, b'\x00')
    payload = json.dumps(payload).encode('utf-8')
    return SecretBox(prepped_key).encrypt(payload, encoder=Base64Encoder).decode('utf-8')