Linking a C++ application to a Java API

Having developed a C++ AES algorithm program to encrypt text files on the server machine, I am now looking to expand its capabilities by enabling file uploads from different machines using a web app.

The web app is created in Java and will interface with the server machine through a Java-based API. When a user clicks the upload button on the web app, it triggers the API to transfer the file to the server machine. So far, this process has been successful for files within the same LAN.

However, I have hit a roadblock. I want the C++ program to automatically recognize when a new file is uploaded to the machine, retrieve it, and initiate the encryption process. How can this be achieved?

My initial thought was to potentially utilize JavaScript, but I am unsure of how to implement this solution.

If more information is needed, please do not hesitate to ask. Any advice or guidance on this matter would be greatly appreciated. Thank you!

Answer №1

Could it be that your Java program is responsible for downloading the file and storing it in a specific directory? If so, why not consider developing a JNI wrapper (a jar library) for your C++ application? Once the download is complete, you can simply instruct your library where to find the file and encrypt it.

Additionally, have you thought about encrypting the byte stream you are receiving and saving the already encrypted bytes directly to disk?

Answer №2

Providing assistance based on my understanding of your query: https://msdn.microsoft.com/enus/library/windows/desktop/aa365261(v=vs.85).aspx

An illustration of this is shown below:

#include <windows.h>
#include <stdio.h>
#define DIR_PATH L"C:\\temp\\files"

void encrypt(WCHAR* fileName);
OVERLAPPED overlapped = {0};
union {
    FILE_NOTIFY_INFORMATION i;
    char d[sizeof(FILE_NOTIFY_INFORMATION)+MAX_PATH];
} fni;

int main()
{
    HANDLE hDirectory;
    BOOL res;
    DWORD bytesReturned;

    // Establish a handle for the designated directory
    hDirectory =  CreateFileW(DIR_PATH, FILE_LIST_DIRECTORY | GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_BACKUP_SEMANTICS,NULL);
    overlapped.hEvent = CreateEvent(0,0,0,0);

    // Continuously monitor activities
    while (1)
    {
        res = ReadDirectoryChangesW(hDirectory,(LPVOID)&fni,sizeof(fni),FALSE,FILE_NOTIFY_CHANGE_SIZE,
                                                                &bytesReturned,&overlapped,NULL);
        // Validate for errors
        if ( res == 0)
        {
            printf("error: %d\n",GetLastError());
            return 1;
        }

        // Check for new file creations within the directory
        GetOverlappedResult(hDirectory,&overlapped,&bytesReturned,TRUE);
        if (fni.i.Action != 0)
            encrypt(fni.i.FileName);
    }
}

//The encryption process takes place here
void encrypt(WCHAR* fileName)
{
    wprintf(L"Insert Encryption Code!\nFileName=%ls\n",fileName);
}

Replace the DIR_PATH variable and make modifications to the encrypt function as needed.

(This marks my first response in this forum ^^)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered while trying to access `cookies.js` file in the `axios` module located at `../node_modules/axios/lib/helpers/`. The specific

Every time I attempt to retrieve data using axios.get(url), an error is thrown. Despite trying numerous solutions, nothing seems to work and this issue has persisted for quite some time. Any assistance that can be provided would be greatly appreciated. Er ...

Using Webpack to manage environment variables in Typescript

Having some issues declaring global variables in Typescript with Webpack's DefinePlugin. Seeking assistance to identify what might be going wrong. Implemented an environment variable in my .bash_profile: export API_KEY_GOOGLE_MAPS=xxxxxxxxxxxxxxxx ...

The step-by-step guide to implementing async/await specifically for a 'for loop'

Is there a way to make 'submitToTheOthers' function run after 'let items = []' has completed, without needing an await within 'submitToTheOthers'? I am considering using await within the for loop in 'submitToTheOthers&apo ...

Clicking on the arrow in an ExtJS split button

I'm having trouble clicking on the arrow of an ExtJS split button using Selenium WebDriver. I've attempted it multiple times without success. Below is a link where you can find the split button. I just need Selenium to click on the arrow so that ...

What is the best way to sort and remove duplicates from a vector containing multiple vectors?

I'm struggling to figure out how to keep only the unique arrays in a vector using standard algorithms. I've tried various approaches, but none seem to be working. Code: include <iostream> #include <vector> #include <array> #in ...

Utilizing $location.search parameters with ng-href for navigation

Something really strange is happening in my code right now. I'm utilizing ng-repeat to generate multiple elements based on an array of objects, like so: <a ng-repeat="report in reports" ng-href="#/report?report={{report.id}}+file=0" ></a> ...

A new C++ function designed to facilitate input editing within a specific data structure

I am currently working on creating a custom Logic Gate data structure in C++, specifically an AND Gate, which consists of three main functions: 1. A function that takes either 1 or 0 as input from the user. 2. A function that calculates and displays the o ...

Rcpp, Decoding the Assigning Error, Exploring the Significance of SEXPREC*

I created the below code using Rcpp //#include <Rcpp.h> #include <RcppArmadilloExtensions/sample.h> #include <random> #include <iostream> using namespace Rcpp; // [[Rcpp::export]] arma::vec SimulateBetaBinomial(int K, arma::vec N ...

Replacing text within nested elements

I am facing an issue with replacing certain elements on my webpage. The element in question looks like this: <div id="product-123"> <h3>${Title}</h3> <div> ${Description} </div> <div> ${P ...

What is the best way to securely transfer data from a Node/Express server to the client using JavaScript, ensuring sanitized HTML and preventing cross-site scripting (X

What is the best method to securely pass data from an Express backend to a client-side JavaScript in order to render it in the DOM using client-side rendering, while also allowing sanitized whitelist HTML and preventing XSS attacks? For example, if the No ...

Is there a way to automatically fill in a text field when an option is chosen from a dropdown menu populated with a list of objects?

When working with a DTO that has attributes id, name, and text, I am creating a list of these DTOs and passing them to my JSP using model.addAttribute. In the JSP, I am rendering a Spring list in the following way: <form:select path="notificationsId" i ...

How can I achieve the same functionality as C# LINQ's GroupBy in Typescript?

Currently, I am working with Angular using Typescript. My situation involves having an array of objects with multiple properties which have been grouped in the server-side code and a duplicate property has been set. The challenge arises when the user updat ...

What is the best way to access the id attribute of a <td> element within a <tr> using jQuery?

Can someone assist me with this issue? Is there a way to get the ID of the first or second td element instead of using a loop? Here is an example: "<tr class='test_point' id="+fileName+"><td><img src='"+ROOT_PATH+"/assets/d ...

When deploying a microservice on an AKS cluster using Spring Boot, an error of UnsupportedClassVersionError is

Encountering an UnsupportedClassVersionError while attempting to deploy a Java Spring Boot microservice on AKS. Using the "kubectl apply -f file.yaml" command for deployment. Even after compiling with the correct compiler version, the issue persists. Unsur ...

Access a secure MS Access database with Workgroup security using UCanAccess

Currently, I am using the UCanAccess driver to establish a connection with an unsecured MS Access database using Knime software. However, I now need to establish a connection with a secured MS Access DB (MDB file) that is protected by a workgroup security ...

What is the best way to display a message on the 403 client side when an email sending fails?

I am attempting to display an alert message when the email is sent successfully or if it fails. If it fails, I receive a 403 status code from the backend. However, I am unsure how to handle this error on the client-side. In the case of success, I receive a ...

An issue with the index bounds has been detected in the ArrayList data structure

I'm faced with the challenge of initializing an array list with a starting size of 10, and I've come up with this code snippet. List<EWSMessage> messages = new ArrayList<EWSMessage>(10); List<EWSMessage> newMessages = new Arra ...

Refresh your textarea content using the replace method in jQuery

My goal is to extract and manipulate specific values within a user-entered code using jQuery. The code includes custom tags called setting, which I want to extract and display in input fields for easy editing. I have successfully retrieved and displayed th ...

Is it possible to obtain a user's public URL using the Facebook API in version 2?

In version 1, it is possible to obtain the user's public link by using the following endpoint: /v1.0/me function testAPI() { console.log('Welcome! Fetching your information....'); FB.api('/me', function(response) { ...

Exploring the World of Images with Javascript

I'm currently working on creating a slideshow using HTML and JavaScript. My goal is to have the image change each time I press a button that I've established (see code below). After reviewing my code multiple times, I still can't figure out ...