Search This Document
Restrict access to persistent store data using code signing keys
Code signing keys can be used to control access to the persistent store. This is a way to restrict or share access with other apps on a BlackBerry smartphone.
- Import the required classes and interfaces.
import java.util.Hashtable; import net.rim.device.api.system.PersistentObject;
- Create a hash ID for the object you want to store in a persistent object.
long MY_DATA_ID = 0x33abf322367f9018L; Hashtable myHashtable = new Hashtable();
- Store the object in the persistent object and protect the object with the CodeSigningKey object. For example, after an app runs the following line of code, only .cod files that are signed with the RSAE .key file can read or overwrite the object in the persistent object.
persistentObject.setContents( new ControlledAccess( myHashtable, key ) );
- Make sure that the object is protected, and invoke getContents using the CodeSigningKey object as a parameter.
Hashtable myHashtable = (Hashtable) persistentObject.getContents( key );
Next topic: Performance of the persistent store
Previous topic: Restricting access to persistent objects