How to Encrypt & Password Protect a Zip File using Node.js

Cloudmersive
2 min readNov 3, 2023

--

Without adequate permissions placed on our Zip Archives, anyone can extract and view our content. It’s important that we protect our most sensitive content with basic security measures.

Using the below code, we can take advantage of a free API that allows us to both encrypt and password protect our zip files in a quick request with minimal code. We just need to structure our request like so:

{
"InputFileContents": "string",
"Password": "string",
"EncryptionAlgorithm": "string"
}

And our response will contain our secured file.

We can structure our API call in two quick steps — starting with SDK installation. We can either run the below command to install the SDK:

npm install cloudmersive-convert-api-client --save

Or we can add the below snippet to our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

After that, we can incorporate the below code examples into our file and authorize our request with a free-tier API key (these allow up to 800 API calls per month with no additional commitment):

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.ZipArchiveApi();

var encryptionRequest = new CloudmersiveConvertApiClient.ZipEncryptionAdvancedRequest(); // ZipEncryptionAdvancedRequest | Encryption request


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.zipArchiveZipEncryptAdvanced(encryptionRequest, callback);

Just like that, we’ve improved our file security.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet