Coder Social home page Coder Social logo

publicbenz / protect Goto Github PK

View Code? Open in Web Editor NEW

This project forked from justkawal/protect

0.0 0.0 0.0 52 KB

Protect is a flutter and dart library for applying and removing password protection on excel files.

License: MIT License

Dart 100.00%

protect's Introduction

protect

Platform Pub Package License: MIT Donate Issue Forks Stars

Protect is a flutter and dart library for applying and removing password protection on excel files.

Table of Contents

Lets Get Started

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  protect: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$  pub get

with Flutter:

$  flutter packages get

3. Import it

Now in your Dart code, you can use:

    import 'package:protect/protect.dart';

Usage

Imports

    import 'dart:io';
    import 'package:protect/protect.dart';
    

Read XLSX File

    var file = "Path_to_pre_existing_Excel_File/excel_file.xlsx";
    var unprotectedExcelBytes = await File(file).readAsBytes();
    or
  //var protectedExcelBytes = await File(file).readAsBytes();
    

Read XLSX from Flutter's Asset Folder

    import 'package:flutter/services.dart' show ByteData, rootBundle;
    
    /* Your blah blah code here */
    
    ByteData data = await rootBundle.load("assets/existing_excel_file.xlsx");
    var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    var unprotectedExcelBytes = await File(file).readAsBytes();
    or
  //var protectedExcelBytes = await File(file).readAsBytes();
    

Apply password protection on XLSX File

  ///
  /// Applying password protection
  /// where `unprotectedExcelBytes` is the bytes of unprotected excel
  ///
  ProtectResponse encryptedResponse = await Protect.encryptUint8List(unprotectedUint8List, '[email protected]');

  var data;
  if (encryptedResponse.isDataValid) {
    data = encryptedResponse.processedBytes;
  } else {
    print('Excel file used for applying password over it is corrupted');
  }
    

Remove password protection on XLSX File

  ///
  /// Applying password protection 
  /// where `protectedUint8List` is the bytes of encrypted excel
  ///
  ProtectResponse decryptedResponse = await Protect.decryptUint8List(protectedUint8List, '[email protected]');
  
  var data;
  if (decryptedResponse.isDataValid) {
    data = decryptedResponse.processedBytes;
  } else {
    print('Either password is wrong for opening the excel file or the Excel file is corrupted');
  }

Saving XLSX File

  // Save the Changes in file
  
  var outputPath = '/Path_to_excel_folder/form_encrypted_file.xlsx';
  await File(outputPath)
    ..create(recursive: true)
    ..writeAsBytes(data);
    

Donate (Thanks for being kind)

protect's People

Contributors

justkawal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.