Sunday, January 27, 2013

Protect Excel Workbook from Unauthorized Access in Java Applications

This technical tip allows developers how to protect a Excel workbook from unauthorized access using Saaspose.Cells REST API in Java applications. Some important steps for performing this task is to build URI to Protect Workbook, sign URI, serialize the JSON request content, Represents Protection Types and use Protection Class above to apply the protection.
Sample Code for protecting Excel workbook from unauthorized access
//build URI to Protect Workbook
string strURI = "http://api.saaspose.com/v1.0/cells/input.xls/protection";
//sign URI
string signedURI = Sign(strURI);
//serialize the JSON request content
Protection protection = new Protection();
protection.setProtectionType(ProtectionType.All);
protection.setPassword("password");
              
String strJSON = "";
Gson gson = new Gson();
              
strJSON = gson.toJson(encryption, Encryption.class);
InputStream responseStream = ProcessCommand(signedURI, "POST", strJSON);
           
String strResponse = StreamToString(responseStream);
//Following is the Protection Class used above
public class Protection
    {
        public Protection()
        {
      
        }
        private ProtectionType ProtectionType;
        private String Password;
      
        public ProtectionType getProtectionType(){return ProtectionType;}
        public String getPassword(){return Password;}
      
        public void setProtectionType(ProtectionType ProtectionType){ this.ProtectionType=ProtectionType;}
        public void setPassword(String Password ){ this.Password=Password;}
     
    }
    /// <summary>
    /// Represents Protection Types
    /// </summary>
    public enum ProtectionType
    {
        All,
        Structure,
        Windows,
        None
    }
Overview: Saaspose.Cells
Saaspose.Cells is a REST API for processing spreadsheets in the cloud. It allows creating, manipulating & converting spreadsheets in web, desktop, mobile & cloud applications. It supports rows, columns, cells, text, data, images, hyperlinks, comments, formulas & many other aspects of spreadsheets. It can be used with any language to incorporate the spreadsheet processing features in any type of business application. It renders spreadsheets & charts to images like JPEG, PNG, SVG, GIF or TIFF etc.
More about Saaspose.Cells
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465

No comments:

Post a Comment