首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件加密在ionic 3中不起作用

文件加密在ionic 3中不起作用
EN

Stack Overflow用户
提问于 2019-08-14 17:47:59
回答 1查看 228关注 0票数 0

我正在尝试加密我的android设备上的文件。然而,在运行代码时,我得到了一个"plugin_not_installed“错误。

我已经使用命令$ ionic cordova plugin add cordova-safe $ npm install --save @I native/file-encryption@4安装了cordova-safe插件

我已经检查了config.xml和package.json中的插件,它确实存在

代码语言:javascript
复制
import { FileEncryption } from '@ionic-native/file-encryption';
constructor(public fileEncryption: FileEncryption){}
this.fileEncryption.encrypt(fileName, AppDefaults.FILEKEY).then(encryptdata=>{
      console.log(encryptdata)
    })

我希望该文件应该被加密,但我得到了一个错误:尝试调用FileEncryption.encrypt,但FileEncryption插件未安装plugin_not_installed

EN

回答 1

Stack Overflow用户

发布于 2020-07-17 15:03:21

错误:

本机:已尝试调用FileEncryption.encrypt,但FileEncryption插件未添加FileEncryption插件:'ionic cordova plugin installed.

  • Install cordova-safe'

Detail

此错误源于'node_modules/@ionic-native/core/decorators/common.js',getPlugin()函数无法检测到cordova-safe或FileEncryption方法,因此请将您的getPlugin()函数替换为此函数

解决方案

从…

代码语言:javascript
复制
    export function getPlugin(pluginRef) {
      if (typeof window !== 'undefined') {
        return get(window, pluginRef);
      }
      return null;
   }

代码语言:javascript
复制
    export function getPlugin(pluginRef) {
    if (typeof window !== 'undefined') {
        let data =  get(window, pluginRef);
        let androidAndios = false;
        window.Ionic.platforms.forEach(platform => {
            if(platform == "android" || platform == "ios" || platform == "hybrid" || platform == "mobile" || platform == "mobile"){
                androidAndios = true;
            }
        });
        if(androidAndios){
            if(data.safe){
                if(data.safe['encrypt'] && data.safe['decrypt']){
                    return data.safe;
                }
            }
        }

        return data;
        
    }
    return null;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57492259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档