【问题标题】:How to save persistent values in a Titanium Appcelerator App如何在 Titanium Appcelerator 应用程序中保存持久值
【发布时间】:2014-10-26 03:15:34
【问题描述】:

我正在尝试找出在使用 Titanium 构建的 Android 移动应用中安全保存用户信息的最佳方法。我对最好的方法感到困惑。

似乎最简单的方法是将其保存为属性。比如……

                Ti.App.Properties.setString('user_name', user.name);
                Ti.App.Properties.setString('user_id', user.id);
                Ti.App.Properties.setString('user_sessionid', user.session_id);

这似乎很棒,因为这些属性是持久化的等等。但是,根据我在其他地方读到的内容,我不确定这是否是安全/最好的方法。

另一种方法是将其保存为全局属性。

                Alloy.Globals.userid = user.id;
                Alloy.Globals.user_name = user.name;

这当然不是持久的,因此用户每次都必须登录。我很想知道其他人在做什么,以及最佳做法是什么。任何见解将不胜感激。谢谢!

【问题讨论】:

    标签: javascript android titanium titanium-mobile appcelerator-mobile


    【解决方案1】:

    我建议你看看 sculejs (https://github.com/dan-eyles/sculejs) - 它是一个用于 javascript 的 noSQL 数据库,它的核心功能之一是它对保存的数据进行加密并确保其安全。

    它不仅仅是为您想要存储的小设置而设计的,而且绝对可以满足您的需求。

    您还可以对您喜欢存储在应用设置中的字符串使用某种散列,并按照您在问题中提到的方式加密/解密您存储的数据。

    【讨论】:

    • 感谢@developer82。 sculejs 看起来真的很酷,我可能最终会使用它。但是,我仍然很想知道是否还有其他选择。值得注意的是,在存储 sessionid 等方面,是否有针对移动应用程序的最佳实践建议。从 Titanium 的角度来看,我希望找到一些明确的指导,但还没有发现任何东西。
    • @DevIntern 好吧,我不确定答案是否在 Titanium 中,而是一种移动开发方法。 iPhone 和 Android 都有存储这些设置的能力——这正是 Titanium SDK 在 javascript 中抽象给你的。
    【解决方案2】:

    毫无疑问,这个模块:https://github.com/benbahrenburg/Securely

    是为 iOS 和 Android 安全存储“小”数据的最佳方式。

    //Require the securely module into your project
    var securely = require('bencoding.securely');
    
    // AES encryption
    var plainTextString = "this is a clear text example string";
    var usingGUID = securely.generateDerivedKey(Ti.Platform.createUUID());  
    Ti.API.info("Derived key using GUID = " + usingGUID);
    var aesEncryptedString = stringCrypto.AESEncrypt(usingGUID,plainTextString);
    Ti.API.info("aesEncryptedString =" + aesEncryptedString);
    
    // later on - decrypt it
    var aesDecryptedString = stringCrypto.AESDecrypt(usingGUID,aesEncryptedString);
    Ti.API.info('aesDecryptedString=' + aesDecryptedString);
    

    模块中还有DES(sha256、sha512)加密方式供您选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多