/*! \Copyright Sertainty Corporation, 2021. All Rights Reserved. \File open_uxp_auth.uxl \Brief This sample shows how to open and interactively authenticate a UXP Object using known prompt/response pairs and read contents of virtual files protected within a UXP Object. \Author Melvin Valdez de la Roca \Date 07/15/2020 \Note Application expects to find the necessary source files in the current working folder. */ replace procedure open_uxp_auth() { bytearray buffer; int appHandle, fileHandle, len; string uxpFileSpec = "sample.uxp"; string copy2Spec = "copy2.pdf"; string fp; printf("\n\nOpening and Authenticating into a UXP interactively\n\n"); printf("Opening new Data\n"); printf("Credentials necessary to access UXP:\n"); printf(" Username = SampleUser@myemail.com\n"); printf(" Challenge 1 = Response 1\n"); printf(" Challenge 2 = Response 2\n"); printf(" ... \n"); printf(" Challenge 10 = Response 10\n\n"); appHandle = sf::openUxp(uxpFileSpec, "ShareReadOnly"); if (errorstring) { printf("\nError opening UXP: %1\n", errorstring); return; } else { printf("You're authorized\n"); } printf("\nExtracting data.pdf to copy2.pdf\n"); fileHandle = sf::openFile(appHandle, "data.pdf"); if (errorstring) { printf("Error opening virtual file: %1\n", errorstring); } fp = file::open(copy2Spec, "wb"); while (sf::readFile(appHandle, fileHandle, buffer, 100000)) { len = strlen(buffer); file::write(buffer, len, 1, fp); } file::close(fp); sf::closeFile(appHandle, fileHandle); if (sf::compareExternalFile(appHandle, "data.pdf", copy2Spec)) { printf("Comparison of data.pdf to copy2.pdf: successful\n"); } else { printf("Comparison of data.pdf to copy2.pdf: failed\n"); } /* Close up again and free handle */ sf::closeUxp(appHandle); printf("You have successfully opened and interactively authenticated into a UXP.\n"); printf("You may try out other advanced samples now.\n"); printf("\nSample finished running\n"); return 0; } open_uxp_auth();