public boolean saveEncryptionKeyData(KeyData data) {
        JSONObject objectToSave = new JSONObject();
        try {
            objectToSave.put(KEY_DPK, DPKEncryptionUtil.byteArrayToHexString(data
                    .getEncryptedDPK()));
            objectToSave.put(KEY_IV, DPKEncryptionUtil.byteArrayToHexString(data.getIv()));
            objectToSave.put(KEY_SALT, DPKEncryptionUtil.byteArrayToHexString(data.getSalt()));
            objectToSave.put(KEY_ITERATIONS, data.iterations);
            objectToSave.put(KEY_VERSION, data.version);

            String valueToSave = objectToSave.toString();

            SharedPreferences.Editor editor = this.prefs.edit();
            editor.putString(preferenceKey, valueToSave);
            editor.commit();

        } catch (JSONException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            return false;
        }

        return true;
    }
public boolean saveEncryptionKeyData ( KeyData data ) { JSONObject objectToSave = new JSONObject ( ) ; try { objectToSave . put ( KEY_DPK , DPKEncryptionUtil . byteArrayToHexString ( data . getEncryptedDPK ( ) ) ) ; objectToSave . put ( KEY_IV , DPKEncryptionUtil . byteArrayToHexString ( data . getIv ( ) ) ) ; objectToSave . put ( KEY_SALT , DPKEncryptionUtil . byteArrayToHexString ( data . getSalt ( ) ) ) ; objectToSave . put ( KEY_ITERATIONS , data . iterations ) ; objectToSave . put ( KEY_VERSION , data . version ) ; String valueToSave = objectToSave . toString ( ) ; SharedPreferences . Editor editor = this . prefs . edit ( ) ; editor . putString ( preferenceKey , valueToSave ) ; editor . commit ( ) ; } catch ( JSONException e ) { LOGGER . log ( Level . SEVERE , e . getLocalizedMessage ( ) , e ) ; return false ; } return true ; }
Save to the {@link SharedPreferences} a {@link KeyData}.
<p/>
Notice that if there is already data in the {@link SharedPreferences} bound to the same
identifier used to create
this storage, the operation will fail.

@param data {@link KeyData} to save to the {@link SharedPreferences}
@return true (success) or false (fail)