React Native
React Native
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 React Native Downloads
import { Crypt2, FileAccess } from '@chilkat/react-native'
async function chilkatExample() {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const crypt = new Crypt2();
crypt.cryptAlgorithm = 'aes';
crypt.cipherMode = 'cbc';
crypt.keyLength = 128;
crypt.paddingScheme = 0;
const ivHex = '000102030405060708090A0B0C0D0E0F';
crypt.setEncodedIV(ivHex, 'hex');
const keyHex = '00010203040506071011121314151617';
crypt.setEncodedKey(keyHex, 'hex');
const dataFile = 'qa_data/zips/HBIQ040615300005.ZIP';
const outFile = 'qa_output/HBIQ040615300005.enc';
const outFile2 = 'qa_output/HBIQ040615300005.ZIP';
await crypt.ckEncryptFileAsync(dataFile, outFile);
await crypt.ckDecryptFileAsync(outFile, outFile2);
const fac = new FileAccess();
const bEqual = fac.fileContentsEqual(dataFile, outFile2);
if (!bEqual) {
console.log('Decrypted file not equal to the original.');
} else {
console.log('Success.');
}
}