Giter Club home page Giter Club logo

cordova-safe's People

Contributors

disusered avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-safe's Issues

FileEncryption plugin is not installed.

i try to install this plugin, but ionic say: "FileEncryption plugin is not installed."
But I installed with:

$ ionic cordova plugin add cordova-safe
$ npm install --save @ionic-native/file-encryption

And I use it as following:

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { FileEncryption } from '@ionic-native/file-encryption';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {

  constructor(public navCtrl: NavController,
              private fileEncryption: FileEncryption,
              public platform: Platform) {

              this.platform.ready().then(() => {


                console.log('Platform ready!!!');

                this.fileEncryption.decrypt('assets/json/secret.json', 'secretKey');
                this.fileEncryption.encrypt('assets/json/secret.json', 'secretKey');

              });

  }

}

Native: tried calling FileEncryption.decrypt, but the FileEncryption plugin is not installed.
Install the FileEncryption plugin: 'ionic cordova plugin add cordova-safe'

This is my Configuration:

cli packages: (C:\Users\username.npm-packages\node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v6.9.4
npm  : 5.6.0
OS   : Windows 10

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

issue using 1.1 on meteor

Seems cordova can't locate the com.facebook.crypto lib. I'm using cordova-safe in a meteor app so this may look a little different than a normal cordova debug output, but under the hood it really is just cordova. com.facebook.crypto.* java lib isn't listed as a dependency. Should it be? am I missing something else? Thank you! error below

[buildconfig] Generating BuildConfig class.
-pre-compile:
     [echo] Set jars path to: /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/CordovaLib/ant-build/classes.jar
-compile:
    [javac] Compiling 31 source files to /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/ant-build/classes
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:21: error: package com.facebook.crypto does not exist
    [javac] import com.facebook.crypto.Crypto;
    [javac]                           ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:22: error: package com.facebook.crypto does not exist
    [javac] import com.facebook.crypto.Entity;
    [javac]                           ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:23: error: package com.facebook.crypto.exception does not exist
    [javac] import com.facebook.crypto.exception.CryptoInitializationException;
    [javac]                                     ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:24: error: package com.facebook.crypto.exception does not exist
    [javac] import com.facebook.crypto.exception.KeyChainException;
    [javac]                                     ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:25: error: package com.facebook.android.crypto.keychain does not exist
    [javac] import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
    [javac]                                            ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:26: error: package com.facebook.crypto.util does not exist
    [javac] import com.facebook.crypto.util.SystemNativeCryptoLibrary;
    [javac]                                ^
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:37: error: cannot find symbol
    [javac]   private Crypto CRYPTO;
    [javac]           ^
    [javac]   symbol:   class Crypto
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:38: error: cannot find symbol
    [javac]   private Entity ENTITY;
    [javac]           ^
    [javac]   symbol:   class Entity
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:96: error: cannot find symbol
    [javac]     } catch (CryptoInitializationException e) {
    [javac]              ^
    [javac]   symbol:   class CryptoInitializationException
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:98: error: cannot find symbol
    [javac]     } catch (KeyChainException e) {
    [javac]              ^
    [javac]   symbol:   class KeyChainException
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:111: error: cannot find symbol
    [javac]       ENTITY = new Entity(password);
    [javac]                    ^
    [javac]   symbol:   class Entity
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:116: error: cannot find symbol
    [javac]       CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
    [javac]                    ^
    [javac]   symbol:   class Crypto
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:116: error: cannot find symbol
    [javac]       CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
    [javac]                               ^
    [javac]   symbol:   class SharedPrefsBackedKeyChain
    [javac]   location: class Safe
    [javac] /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/src/com/disusered/Safe.java:116: error: cannot find symbol
    [javac]       CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
    [javac]                                                                       ^
    [javac]   symbol:   class SystemNativeCryptoLibrary
    [javac]   location: class Safe
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 14 errors
Command finished with error code 8: /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/cordova/run --device
ERROR running one or more of the platforms: Error: /media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/cordova/run: Command failed with exit code 8
You may not have the required environment or OS to run this project
BUILD FAILED
/Users/bgrayburn/.meteor/android_bundle/android-sdk/tools/ant/build.xml:716: The following error occurred while executing this line:
/Users/bgrayburn/.meteor/android_bundle/android-sdk/tools/ant/build.xml:730: Compile failed; see the compiler error output for details.
Total time: 3 seconds
/media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: ant with args: debug,-f,/media/Storage/emocha/platform-midot-mobile/app/.meteor/local/cordova-build/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen

encrypt image fileURL return error

I have this app where I take picture or select it from gallery then move it into file-system , save the imgpath for the image into sqlite db and display it, I'm trying to encrypt the imgPath for the image which is saved on ccordova.file.datadirectory ,but I keep getting "Error with cryptographic operation".
any help would be appreciated

var db = null;
angular.module('starter', ['ionic', 'ngCordova']) 
    .run(function($ionicPlatform, $cordovaSQLite) {    
        $ionicPlatform.ready(function() {      
            try {        
                db = $cordovaSQLite.openDB({          
                    name: "my.db",
                              location: 'default'        
                });        
                $cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS imageTable " + "(id integer primary key, image text)");      
            } catch (e) {        
                alert(e);      
            } finally {       }

            if (window.cordova && window.cordova.plugins.Keyboard) {

                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);


                cordova.plugins.Keyboard.disableScroll(true);
            }
            if (window.StatusBar) {
                StatusBar.styleDefault();
            }
        });
    })



    .controller('ImageCtrl', function($scope, $rootScope, $state, $stateParams, $cordovaDevice, $cordovaFile, $ionicActionSheet, $cordovaCamera, $cordovaFile, $cordovaDevice, $ionicPopup, $cordovaActionSheet, $cordovaSQLite, $interval) {




        var imagesP = [];

        //$scope.images = [];


        $scope.showAlert = function(title, msg) {
            var alertPopup = $ionicPopup.alert({
                title: title,
                template: msg
            });
        };


        $scope.loadImage = function() {

            var options = {
                title: 'Select Receipts Image ',
                buttonLabels: ['Gallery', 'Take photo', 'File System'],
                addCancelButtonWithLabel: 'Cancel',
                androidEnableCancelButton: true,
            };
            $cordovaActionSheet.show(options).then(function(btnIndex) {
                var type = null;
                if (btnIndex === 1) {
                    type = Camera.PictureSourceType.PHOTOLIBRARY;
                } else if (btnIndex === 2) {
                    type = Camera.PictureSourceType.CAMERA;
                }
                if (type !== null) {
                    $scope.selectPicture(type);
                }
            });
        }




        // Take image with the camera or from library and store it inside the app folder
        // Image will not be saved to users Library.
        $scope.selectPicture = function(sourceType) {


            var options = {
                quality: 75,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: sourceType,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                correctOrientation: true,
                targetWidth: 800,
                targetHeight: 800,
                popoverOptions: CameraPopoverOptions, // for IOS and IPAD
                saveToPhotoAlbum: false
            };

            $cordovaCamera.getPicture(options).then(function(imagePath) {
                    // Grab the file name of the photo in the temporary directory
                    var currentName = imagePath.replace(/^.*[\\\/]/, '');
                    //  alert(currentName);

                    //Create a new name for the photo to avoid duplication
                    var d = new Date(),
                        n = d.getTime(),
                        newFileName = n + ".jpg";
                    //alert(newFileName);
                    // If you are trying to load image from the gallery on Android we need special treatment!
                    if ($cordovaDevice.getPlatform() == 'Android' && sourceType === Camera.PictureSourceType.PHOTOLIBRARY) {
                        window.FilePath.resolveNativePath(imagePath, function(entry) {
                            window.resolveLocalFileSystemURL(entry, success, fail);

                            function fail(e) {
                                console.error('Error: ', e);
                            }

                            function success(fileEntry) {
                                var namePath = fileEntry.nativeURL.substr(0, fileEntry.nativeURL.lastIndexOf('/') + 1);
                                // Only copy because of access rights
                                $cordovaFile.copyFile(namePath, fileEntry.name, cordova.file.dataDirectory, newFileName).then(function(success) {
                                    //  $scope.image = newFileName;
                                    var imgPath = cordova.file.dataDirectory + newFileName;

                                    $scope.add(imgPath);
                               $scope.encryptFile(imgPath);




                                }, function(error) {
                                    $scope.showAlert('Error', error.exception);
                                });
                                //      alert( fileEntry.nativeURL);

                            };
                        });
                    } else {
                        var namePath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
                        // Move the file to permanent storage
                        $cordovaFile.moveFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(function(success) {
                            // $scope.image = newFileName;
                            //$scope.images.push(newFileName);
                                    var imgPath = cordova.file.dataDirectory + newFileName;
                            $scope.add(imgPath);




                        }, function(error) {
                            $scope.showAlert('Error', error.exception);
                        });

                    }
                },
                function(err) {
                    // Not always an error, maybe cancel was pressed...
                })
        };

        $scope.add = function(path) {             
                if (imagesP != null) {          
                    $cordovaSQLite.execute(db, "INSERT INTO imageTable (images) VALUES(?)", [path] );        
                }        
                alert("Inserted.");      
            },
            function(e) {        
                alert(e);      
            };

$scope.encryptFile = function(file){


            var safe = cordova.plugins.disusered.safe,
                key = 'someKeyABC';


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


            }

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

            safe.encrypt(file, key, success, error);
            }



          
        $scope.ShowAllData = function() {     
            $scope.images = [];      
            $cordovaSQLite.execute(db,"SELECT images FROM imageTable").then(function(res) {          
                if (res.rows.length > 0) {            
                    for (var i = 0; i < res.rows.length; i++) {              
                        $scope.images.push({                
                            id: res.rows.item(i).id,
                            image: res.rows.item(i).images

                                          
                        });            
                    }          
                }        
            },         function(error) {          
                alert(error);        
            }      );

             
        } 

build error after install this plugin

:app:compileDebugJavaWithJavac
..\youtube-download\platforms\android\app\src\main\java\com\disusered\Safe.java:26: error: package com.facebook.android.crypto.keychain does not exist
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
^
F:\santanu\youtube-download\platforms\android\app\src\main\java\com\disusered\Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
2 errors
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    27 actionable tasks: 1 executed, 26 up-to-date
    Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 46s
(node:3416) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
F:\santanu\youtube-download\platforms\android\app\src\main\java\com\disusered\Safe.java:26: error: package com.facebook.android.crypto.keychain does not exist
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
^
F:\santanu\youtube-download\platforms\android\app\src\main\java\com\disusered\Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
2 errors

java.lang.ClassNotFoundException: com.disusered.Safe

Hi, I am trying out the plugin (using your example in the readme), but I keep getting this error in adb logs:

W/System.err(30861): java.lang.ClassNotFoundException: com.disusered.Safe
W/System.err(30861):    at java.lang.Class.classForName(Native Method)
W/System.err(30861):    at java.lang.Class.forName(Class.java:308)
W/System.err(30861):    at java.lang.Class.forName(Class.java:272)
W/System.err(30861):    at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:487)
W/System.err(30861):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:167)
W/System.err(30861):    at org.apache.cordova.PluginManager.exec(PluginManager.java:120)
W/System.err(30861):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(30861):    at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err(30861):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(30861):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err(30861):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(30861):    at android.os.Looper.loop(Looper.java:135)
W/System.err(30861):    at android.os.HandlerThread.run(HandlerThread.java:61)
W/System.err(30861): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.disusered.Safe" on path: DexPathList[[zip file "/data/app/io.cordova.hellocordova-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
W/System.err(30861):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err(30861):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err(30861):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err(30861):    ... 13 more
W/System.err(30861):    Suppressed: java.lang.ClassNotFoundException: com.disusered.Safe
W/System.err(30861):        at java.lang.Class.classForName(Native Method)
W/System.err(30861):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
W/System.err(30861):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
W/System.err(30861):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
W/System.err(30861):        ... 14 more
W/System.err(30861):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I/System.out(30861): Error adding plugin com.disusered.Safe.
W/System.err(30861): java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
W/System.err(30861):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err(30861):    at org.apache.cordova.PluginManager.exec(PluginManager.java:120)
W/System.err(30861):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(30861):    at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err(30861):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(30861):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err(30861):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(30861):    at android.os.Looper.loop(Looper.java:135)
W/System.err(30861):    at android.os.HandlerThread.run(HandlerThread.java:61)

I use the cordova cli, and tried removing and readding the plugin as well as removing and readding the android platform, still no luck. I ran the app on the emulator as well as my android device (both running 5.1).

404 Not Found: cordova-safe

Hi,

I added the plugin to my cordova project and it is shown in the plugin directory.
But I get this error when trying to compile the project.

When I type "cordova plugins" in the project directory I get the following output:

cordova-safe 1.0.6 "Safe"
org.apache.cordova.camera 0.3.6 "Camera"
org.apache.cordova.device 0.3.0 "Device"
org.apache.cordova.file 1.3.3 "File"
org.apache.cordova.file-transfer 0.4.8 "File Transfer"
org.apache.cordova.geolocation 0.3.12 "Geolocation"
org.apache.cordova.network-information 0.2.15 "Network Information"
org.apache.cordova.splashscreen 1.0.0 "Splashscreen"

Where is the error?

Thx, Martin

error code 1 on encrypt

So i've got the lib up and in the dom in android, but I'm consistently getting an error code 1 when running encrypt.

here's my code:

Meteor.enc.safe.encrypt = (fn)->
  console.log "about to encrypt: "+fn
  success = (encryptedFile) ->
    console.log 'Encrypted file: ' + encryptedFile
    return
  error = (c)->
    console.log 'Error with encryption operation, code: ' + c.toString()
    return

  Meteor.enc.safe.safe.encrypt fn, "someKey", success, error

I'm recording a video using the cordova-plugin-media-capture plugin then using the cordova-plugin-file plugin to resolve the fileEntry object. From that I've tried calling the above with:

-the fileEntry.nativeURL property (ex. "file:///storage/emulated/0/DCIM/Camera/VID_20150806_122744.3gp")
-the fileEntry.fullPath property (ex. "/DCIM/Camera/VID_20150806_122744.3gp")
-the fileEntry.toInternalURL() path (ex. "cdvfile://localhost/persistent/DCIM/Camera/VID_20150806_123214.3gp")

didn't really expect the last one to work but figured I'd try. All of these return an error code 1. Any idea what might be going on? I expected the nativeURL to be the right thing to pass, but no luck.

iOS examples

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?

No callback called with encrypt

Neither of the callbacks provided to safe.encrypt are getting called.

Info:

OS: Windows 7
Device:
    OnePlus One
    Android version: 5.0.2

$ cordova --version
    5.1.1
$ cordova plugins list
    cordova-plugin-file 2.1.0 "File"
    cordova-plugin-whitelist 1.0.0 "Whitelist"
    cordova-safe 1.1.1 "Safe"

Code to reproduce the issue:

var
    onDeviceReady = function () {
        // create a file in the persistent storage
        window.requestFileSystem(window.PERSISTENT, 5 * 1024 * 1024, onInitFs, onError);
    },
    onError = function (e) {
        console.error('Error:', e, e.code);
    },
    onInitFs = function (fs) {
        console.log('Opened file system: ' + fs.name);

        fs.root.getFile('userData.json', {create: true, exclusive: false}, function (fileEntry) {
            fileEntry.createWriter(function (fileWriter) {
                fileWriter.onwriteend = onFileWriteComplete;
                fileWriter.onerror = onError;

                // Write a file containing some test data
                fileWriter.write(new Blob(
                        [JSON.stringify({some: 'data'})],
                        {type: 'application/json'})
                );
            }, onError);
        }, onError);
    },
    onFileWriteComplete = function (file) {
        // here the file should be created and available on the device
        var safe = cordova.plugins.disusered.safe,
            key = 'someKey',
            onEncryptSuccess = function (encryptedFile) {
                console.log('Encrypted file: ' + encryptedFile);
            };
        // file.target.localURL value is "cdvfile://localhost/persistent/userData.json"
        safe.encrypt(file.target.localURL, key, onEncryptSuccess, onError);
    };

document.addEventListener('deviceready', onDeviceReady, false);

In the code above onEncryptSuccess or onError should be called.
The function onFileWriteComplete is called and the file exists on the device with the rights: -rw-rw----.

Error while build development - ionic 1.

Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

How to solve this

Plugin not installed

HI i am using this plugin in my ionic 3 project but it is showing plugin not installed
ERROR Error: Uncaught (in promise): plugin_not_installed

Plugin not compiling on Android

Tried plugin with cordova-android 7.1.0 and cordova 8.0.0.

Getting this error at compile time:

\platforms\android\app\src\main\java\com\disusered\Safe.java:26: error: package com.facebook.android.crypto.keychain does not exist
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
^
\platforms\android\app\src\main\java\com\disusered\Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 53s
(node:17028) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code.

conflicting types for 'SecRandomCopyBytes'

Anyone else seen this? Using Xcode 9.2

Ionic project

/app/Plugins/cordova-safe/RNCryptor.m:31:12: error: conflicting types for 'SecRandomCopyBytes' extern int SecRandomCopyBytes(SecRandomRef rnd, size_t count, uint8_t *bytes) __attribute__((weak_import)); ^ In module 'Security' imported from /app/Plugins/cordova-safe/RNCryptor.h:30: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecRandom.h:59:5: note: previous declaration is here int SecRandomCopyBytes(SecRandomRef __nullable rnd, size_t count, void *bytes) ^ /app/Plugins/cordova-safe/RNCryptor.m:361:7: warning: comparison of function 'SecRandomCopyBytes' not equal to a null pointer is always true [-Wtautological-pointer-compare] if (SecRandomCopyBytes != NULL) { ^~~~~~~~~~~~~~~~~~ ~~~~ /app/Plugins/cordova-safe/RNCryptor.m:361:7: note: prefix with the address-of operator to silence this warning if (SecRandomCopyBytes != NULL) { ^ &

package com.facebook.android.crypto.keychain does not exist

After install plugin Ionic 3 app cannot run. it getting error

Error: cmd: Command failed with exit code 1 Error output:
G:\Android\TestProject\platforms\android\src\com\disusered\Safe.java:26: error: package com.facebook.android.crypto.keychain does not exist
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
^
G:\Android\TestProject\platforms\android\src\com\disusered\Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: G:\Android\TestProject\platforms\android\src\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Mixed licensing

Hi,

Looking over the src folder I noticed that the code for Android and iOS is licensed as GPL2, however the LICENSE file in the root is MIT. Is that intentional?

Regards
Phil

Plugin not working

Hi, I am trying to install this plugin with Ionic but I get this error when I try to build the project just by instaling the plugin.

Error is:

`C:\Users\Zel\Desktop\a\platforms\android\src\com\disusered\Safe.java:120: error: cannot find symbol

  CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
                          ^

symbol: class SharedPrefsBackedKeyChain
location: class Safe
Note: Some input files use or override a deprecated API.
:compileDebugJavaWithJavac FAILED

Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

BUILD FAILED

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Total time: 11.002 secs
(node:14276) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\Zel\Desktop\a\platforms\android\src\com\disusered\Safe.java:26: error: package com.facebook.android.crypto.keychain does not exist
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
^
C:\Users\Zel\Desktop\a\platforms\android\src\com\disusered\Safe.java:120: error: cannot find symbol
CRYPTO = new Crypto(new SharedPrefsBackedKeyChain(CONTEXT), new SystemNativeCryptoLibrary());
^
symbol: class SharedPrefsBackedKeyChain
location: class Safe
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    at ChildProcess.whenDone (C:\Users\Zel\Desktop\a\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
    (node:14276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch
    block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:14276) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`

Cordova 6.0.0 Android 5.1.1 IOS 3.8.0/4.0.1 error code 1 on en-/decrypt

I am using OS X and started with the quick start guide for ionic here.
What i have done:

  1. "ionic start myApp sidemenu".
  2. cordova plugin add cordova-plugin-file
  3. cordova plugin add cordova-safe
  4. Changed PlaylistsCtrl to:
    `.controller('PlaylistsCtrl', function($scope) {
    $scope.playlists = [
    { title: 'Reggae', id: 1 },
    { title: 'Chill', id: 2 },
    { title: 'Dubstep', id: 3 },
    { title: 'Indie', id: 4 },
    { title: 'Rap', id: 5 },
    { title: 'Cowbell', id: 6 }
    ];
    document.addEventListener('deviceready', onDeviceReady, false);
    function onDeviceReady() {
    var p = cordova.file.dataDirectory + 'steuern-guide.pdf';
        console.log('$ionicView.afterEnter');
        var safe = cordova.plugins.disusered.safe,
        key = 'someKey';
        function success(encryptedFile) {
          console.log('Encrypted file: ' + encryptedFile);

        }

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

        console.log('Path: ' + p);

        safe.decrypt(p, key, success, error);
    }

})`

  1. Tested android 3.8.0. and 4.0.1

Result:
Whatever i do, i get Error with cryptographic operation: 1.
At first i thought i am working on the wrong path, but a test with resolveLocalFileSystemURL and FIleEntry.moveTo showed that i can rename the corresponding file. So i can access it with r/w rights.

Expected Result:
Encrypted version of the file

I have uploaded the current situation here, everything except the builded files.

Windows encryption tool

I want to encrypt my files in the server and after downloaded with my ionic app decrypt it with this plugin.

Is there a tool in windows that encrypts the files in the format of this plugin?

Cordova-Safe does not work anymore!

After hours of investigation, I have come to the conclusion that the cryptsetup error lies with cordova-safe.
I followed the official documentation very pedantic.
It still did not work! I even started 2 new projects from Scratch!
Just to check if I made a mistake or if something was wrong with npm.

Unfortunately, it is definitely the plugin which does not work anymore!

I really hope very much that cordova-safe is further developed!

Detailed information: https://stackoverflow.com/questions/44969832/is-cordova-safe-still-working-with-ionic3

Cannot read property 'disusered' of undefined

Hi Guys,

After installing plugin in my cordova app, its giving me "Uncaught TypeError: Cannot read property 'disusered' of undefined" on "var safe = cordova.plugins.disusered.safe".

plugin is installed properly, still getting this error.

Please provide some information about it, how to solve this error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.