Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final zip = CkZip();

  try {
    zip.newZip('test.zip');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  zip.setPassword('secret');
  zip.passwordProtect = true;

  final saveExtraPath = false;
  zip.addFile('/temp/hamlet.xml', saveExtraPath);

  try {
    zip.writeZipAndClose();
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Zip Created!');
}