Simple file encryption for Cordova.
$ cordova plugin add https://github.com/tsaokuoyang/cordova-safe
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);
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);
- 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 enc -d -aes-[128|192|256]-ctr -nopad -in 1404177327783.jpg.enc -out 1404177327783.jpg -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000
- fix for ios
MIT © Carlos Rosquillas