def decrypt_payload(secret_key, encrypted_data):
    'Return a decrypted payload given a key and a string of encrypted 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')
    decrypted_data = SecretBox(prepped_key).decrypt(encrypted_data, encoder=Base64Encoder)
    decrypted_data = decrypted_data.decode('utf-8')
    return json.loads(decrypted_data)
Return a decrypted payload given a key and a string of encrypted data.
def decrypt_payload(secret_key, encrypted_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')
    decrypted_data = SecretBox(prepped_key).decrypt(encrypted_data, encoder=Base64Encoder)
    decrypted_data = decrypted_data.decode('utf-8')
    return json.loads(decrypted_data)