2

我需要安全地存储私人用户数据,以便它可以在我的应用程序启动和设备重置期间持续存在。

这将是一个字符串,我猜最多大约 1000 个字符。

有人告诉我我可以为此使用 RIM KeyStore API。

好吧,我花了几个小时在谷歌上搜索有关 RIM KeyStore API 使用的任何指南。JDE 示例不包含对此有用的任何内容。

看起来这在BB开发中是很少见的,所以几乎没有官方信息。

我读了这个这个。据我了解,对我来说最好的选择是使用 PersistableRIMKeyStore (它在设备重置后仍然存在)。但是,我无法弄清楚实现应该是什么。

任何人都可以帮助提供示例代码或指向我一些指南吗?另外,对于我的任务,也许有更好/更简单的方法/方法,所以,请让我知道。

非常感谢提前!!!

4

2 回答 2

1

如果您使用与“PersistentStoreDemo”相同的商店,如果您不知道可以通过转到文件 -> 导入 -> Blackberry Samples 来获得,您可以对商店中的信息进行加密。最重要的是,如果用户启用了内容保护,您可以使用 ContentProtectedHashtable 自动知道该信息将被加密。因此,在没有内容保护的情况下,信息将被加密一次,开启后,它将被双重加密,并以难以猜测的应用名称空间的长哈希存储(显然,因为要注册您需要它的商店)。以下是我使用的:

package ca.dftr.phillyd.lib.persistables;

import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.util.ContentProtectedHashtable;
import net.rim.device.api.util.Persistable;

/**
 * Basic class for storing application specific information. 
 * Information such as application settings or whether the license agreement was accepted.
 * For more complex and specific classes they should be implemented separately and implement persistable 
 * @author deforbes
 */
public class AppInfo extends ContentProtectedHashtable  implements Persistable {

    private String _appName = null;
    private String _version = null;

    /**
     * Constructs the application info, creates and persists a hashtable for application settings.
     * @param uniqueHexAppIdentifier Can be automatically created in resource class (BUNDLE_ID) or generated using other unique information.
     */
    public AppInfo() {    
        ApplicationDescriptor appDesc = ApplicationDescriptor.currentApplicationDescriptor();
        _appName = appDesc.getName();
        _version = appDesc.getVersion();
    }

    /**
     * Get the Name of the application
     * @return The application name from the app descriptor
     */
    public String getName()
    {
        return _appName;
    }

    /**
     * Get the Version of the application
     * @return The application version from the app descriptor
     */
    public String getVersion()
    {
        return _version;
    }
}

以及一类常量(如果需要,可以包含在上面)。例如,从我的 PhillyD 应用程序中:

包 ca.dftr.phillyd.lib.persistables;

/**
 * Keys for the AppInfo array
 * @author deforbes
 */
public class AppInfoKeys {
    public static final String QUALITY = "Quality";
    public static final String CHANNEL = "Channel";
    public static final String CHANNEL_NAME = "Channel_Name";
    public static final String SEARCH = "Search";
    public static final String LICENSE_ACCEPTED = "isLicenseAccepted";
    public static final String VIDEOS_PER_PAGE = "NumPerPage";
    public static final Boolean DOWNLOAD_THUMBS = new Boolean(true);
}
于 2011-08-21T05:35:44.507 回答
0

PersistableRIMKeyStore 用于持久化 RIM 密钥库。要在重置期间保留用户数据,您只需要使用 PersistentStore,如果您希望保护 deta,您可以使用 ContentProtectedHashtable 或 ContentProtectedVector。

于 2011-08-21T19:22:46.120 回答