6.2 Lock/Unlock File Text

6.2.1 Read a file as text

The locked/unlocked file can be read as text as shown in the code snippet.

let fileInfoObject = { "fileText":"", "metaData":"" }

function readFileAsText(){
  var file = document.getElementById("file").files[0];
  var reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onload = function () {
    var fileData=reader.result;
    fileMetadata=fileData.split(",")[0]; //fileMetadata is prepend to the file text and is separated using a comma(,)
    fileText = fileData.replace(fileMetadata+",",""); // Remove fileMetadata along with ","
    fileInfoObject = {
        "fileText":fileText,
        "metaData":fileMetadata
      }
    };
}

6.2.2 Write fileText to a file

The locked/unlocked file text can be written back to the file as shown in the code snippet.

6.2.3 Lock File Text

The lockFileText function locks a file data as text with default BayunEncryptionPolicy and BayunKeyGenerationPolicy dictated by company settings.

The function takes the following parameters :

  • sessionId : Unique SessionId which is received in the login/registration function response.

  • fileText : File text to be locked. You can use the utility function readFileAsText to read file as file text.

6.2.4 Lock File Text with Encryption Policy, Key Generation Policy

The lockFileText function with encryption policy, key generation policy as parameters locks a file data as text. The function takes the following parameters :

  • sessionId : Unique SessionId which is received in the login/registration function response.

  • fileText : File text to be locked. You can use the utility function readFileAsText to read file as file text.

  • encryptionPolicy : BayunEncryptionPolicy determines the key to be used to generate the lockingKey.

  • keyGenerationPolicy : BayunKeyGenerationPolicy determines the policy to generate the lockingKey.

  • groupId : GroupId is required if encryptionPolicy is GROUP.

If encryptionPolicy is other than GROUP then groupId should be an empty string.

6.2.5 Unlock File Text

The unlockFileText function unlocks a locked file data as text. The function takes the following parameters :

  • sessionId : Unique SessionId which is received in the login/registration function response.

  • fileText : File text to be unlocked. You can use the utility function readFileAsText to read locked file as file text.

Last updated

Was this helpful?