Dart
Dart
Encrypt / Decrypt a File and Verify it has not Changed
See more Encryption Examples
Demonstrates how to encrypt and decrypt a file, and verify it has not changed.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final crypt = CkCrypt2();
crypt.cryptAlgorithm = 'aes';
crypt.cipherMode = 'cbc';
crypt.keyLength = 128;
crypt.paddingScheme = 0;
final ivHex = '000102030405060708090A0B0C0D0E0F';
crypt.setEncodedIV(ivHex, 'hex');
final keyHex = '00010203040506071011121314151617';
crypt.setEncodedKey(keyHex, 'hex');
final dataFile = 'qa_data/zips/HBIQ040615300005.ZIP';
final outFile = 'qa_output/HBIQ040615300005.enc';
final outFile2 = 'qa_output/HBIQ040615300005.ZIP';
crypt.ckEncryptFile(dataFile, outFile);
crypt.ckDecryptFile(outFile, outFile2);
final fac = CkFileAccess();
final bEqual = fac.fileContentsEqual(dataFile, outFile2);
if (!bEqual) {
print('Decrypted file not equal to the original.');
} else {
print('Success.');
}
}