Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets regarding Encrypting or Decrypting the PDF files using Aspose.PDF Cloud SDK for Java
This Gist contains code snippets regarding Encrypting or Decrypting the PDF files using Aspose.PDF Cloud SDK for Java
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/
String clientId = "a41d01ef-dfd5-4e02-ad29-bd85fe41e3e4";
String clientSecret = "d87269aade6a46cdc295b711e26809af";
// createPdfApi instance
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// input PDF document
String name = "PdfWithTable.pdf";
// Load the file from local system
File file = new File("/Users/nayyershahbaz/Downloads/" + name);
// upload the file to cloud storage
FilesUploadResult uploadResponse = pdfApi.uploadFile(name, file, null);
// base64 encoded user and owner passwords
String userPasswordBase64encoded = "dXNlciAkXlBhc3N3b3JkISY="; //user $^Password!&
// call API to Decrypt PDF
AsposeResponse response = pdfApi.postDecryptDocumentInStorage(name, userPasswordBase64encoded, null,null);
// Print API response in console
System.out.println(response);
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/
String clientId = "a41d01ef-dfd5-4e02-ad29-bd85fe41e3e4";
String clientSecret = "d87269aade6a46cdc295b711e26809af";
// createPdfApi instance
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// input PDF document
String name = "PdfWithTable.pdf";
// Load the file from local system
File file = new File("/Users/nayyershahbaz/Downloads/" + name);
// upload the file to cloud storage
FilesUploadResult uploadResponse = pdfApi.uploadFile(name, file, null);
// base64 encoded user and owner passwords
String userPasswordBase64encoded = "dXNlciAkXlBhc3N3b3JkISY="; //user $^Password!&
String ownerPasswordBase64encoded = "b3duZXJcLy8/ICQxMl5QYXNzd29yZCEm"; //owner\//? $12^Password!&
// call API to encrypt PDF
AsposeResponse response = pdfApi.postEncryptDocumentInStorage(name, userPasswordBase64encoded, ownerPasswordBase64encoded,
CryptoAlgorithm.AESX128.getValue(), null, null, null, null);
// Print API response in console
System.out.println(response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment