/cordova-safe

File encryption for Cordova.

Primary LanguageObjective-CMIT LicenseMIT

cordova-safe

Build Status Code Climate

Simple file encryption for Cordova.

Install

$ cordova plugin add https://github.com/tsaokuoyang/cordova-safe

Usage

var safe = cordova.plugins.disusered.safe,
    hexKey = '00000000000000000000000000000000', // some hex key (16 bytes for 128, 24 bytes for 192, 32 bytes for 256)
    hexIv  = '00000000000000000000000000000000'; // some hex iv


function success(encryptedFile) {
  console.log('Encrypted file: ' + encryptedFile);

  safe.decrypt(encryptedFile, dstFile, hexKey, hexIv, function(decryptedFile) {
    console.log('Decrypted file: ' + decryptedFile);
  }, error);
}

function error() {
  console.log('Error with cryptographic operation');
}

safe.encrypt('file:/storage/sdcard/DCIM/Camera/1404177327783.jpg', 'file:/storage/sdcard/DCIM/Camera/1404177327783.jpg.enc', hexKey, hexIv, success, error);

API

The plugin exposes the following methods:

cordova.plugins.disusered.safe.encrypt(file, destination_file, hexKey, hexIv, success, error);
cordova.plugins.disusered.safe.decrypt(file, destination_file, hexKey, hexIv, success, error);

Parameters:

  • file: A string representing a local URI
  • dst_file: A string representing a local URI ( destination file )
  • hexKey: A key for the crypto operations
  • hexIv: A iv for the crypto operations
  • success: Optional success callback
  • error: Optional error callback

OpenSSL

openssl enc -d -aes-[128|192|256]-ctr -nopad -in 1404177327783.jpg.enc -out 1404177327783.jpg -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000

Issues

  • fix for ios

License

MIT © Carlos Rosquillas