disusered / cordova-safe

File encryption for Cordova.
MIT License
35 stars 22 forks source link

iOS examples #1

Closed enricodeleo closed 9 years ago

enricodeleo commented 9 years ago

Hi! I've just started testing this plugin on iOS and it looks very promising. I was wondering if someone could share some example usage for iOS since it doesn't seem to work (at least on the emulator).

For example, I'm using it within angular and doin' something like that:

controller('Controller', [
  '$scope',
  '$cordovaFile',
  function($scope, $cordovaFile) {
    var safe = cordova.plugins.disusered.safe,
    key = 'myKey';
    $cordovaFile.checkFile( cordova.file.dataDirectory, 'file.enc' )
      .then(function (success) {
        safe.decrypt(success.nativeURL, key, function(decryptedFile) {
          $scope.img = decryptedFile;
        });
      }, function (error) {
        console.log(error);
    });
}]);

What I expect is to read an encrypted image and embed it in my current view. I use the file plugin to check if the file actually exists and tried both fullPath and nativeURL but it still doesn't seem to work.

Any hint?

Another question, if you don't mind: do this plugin decrypt the file in-place or is it possible to read it on the fly leaving the original file untouched?

VJAI commented 9 years ago

It don't work in emulator. I've used this plugin in a hybrid mobile app and it is open sourced. You can look at the source code here https://github.com/VJAI/Safe/blob/master/src/js/adapters/crypto.js

disusered commented 9 years ago

Hi, as noted it won't work on the emulator due to differences in architecture. Let me know if it works on a device, if not I'll set up a basic Angular/Cordova project to debug it. As for the file, it currently works in-place, I will look at your recommendation for leaving the original file untouched.

enricodeleo commented 9 years ago

Thank you for your replies. I read the @VJAI 's code. As far as I seen that app uses SimpleCrypto. With SimpleCrypto I have to read the file as text and decrypt the content as string but it works. Do you think that if I would go with coedova-safe I'd gain in performances?

disusered commented 9 years ago

I wrote SimpleCrypto before cordova-safe, they both use RNCryptor on iOS but SimpleCrypto additionally outputs to base64, on Android cordova-safe uses Facebook Conceal which is supposed to be faster than SimpleCrypto's JNCryptor.

enricodeleo commented 9 years ago

Thank you for all the good advices!

amrayoub commented 7 years ago

@enricodeleo i'm having the same issue like yours ,i wanna encrypt the img path but i get encrypting error , can you please share some code sample