Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active June 6, 2021 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/7d2346be5e4914a1f854cfcbc4ff158b to your computer and use it in GitHub Desktop.
Save aspose-cloud/7d2346be5e4914a1f854cfcbc4ff158b to your computer and use it in GitHub Desktop.
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