Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:15:32+00:00 2026-06-11T16:15:32+00:00

I’m using a custom subclass of SharedPreferences to encrypt my saved settings in the

  • 0

I’m using a custom subclass of SharedPreferences to encrypt my saved settings in the app, similar to what’s being done in the second response here: What is the most appropriate way to store user settings in Android application

The number of preferences I have to save is growing. Before I was just using a custom view to update these preferences but that is going to become cumbersome and I want to use PreferenceActivity or PreferenceFragment instead. Problem is, it does not seem that there is a way to have either of those classes access my data using my subclass, meaning that the data it pulls from the default preferences file is going to be gibberish as it wasn’t decrypted.

I’ve found that some people have created custom implementations of Preference that encrypt the data there, but I’d prefer not to do that as the data is already being encrypted/decrypted in my SharedPreferences subclass and I’d like to keep it that way. I’ve also been looking over the source code of PreferenceActivity and PreferenceManager and I’m not sure the best way to approach this.

Has anyone else had any luck accomplishing something like this and have any suggestions as to where I might start?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:15:33+00:00Added an answer on June 11, 2026 at 4:15 pm

    I think by keeping your encryption in the SharedPrefs subclass that you already have, you limit the modularity and the separation of concerns.

    So I would suggest reconsidering sub-classing the preference classes themselves (such as CheckBoxPreference) and perform your calculation there.

    Ideally you could also use some type of composition or a static utility so that while you might have to subclass each type of preference you use, you can use a single place to perform the encryption/decryption calculations. This would also allow you more flexibility in the future if you need to encrypt or decrypt some other data or if the API changes.

    For sub-classing maybe you could do this:

    So for example:

    class ListPreferenceCrypt extends ListPreference
    {
        ListPreferenceCrypt (Context context, AttributeSet attrs)   {
            super ( context, attrs );
        }
        ListPreferenceCrypt (Context context)   {
            super ( context );
        }
    
        @Override
        public void setValue( String value )
        {
            //encrypt value
            String encryptedVal = MyCryptUtil.encrypt(value);
            super.setValue ( encryptedVal );
        }
    
        @Override
        public String getValue( String key )
        {
            //decrypt value
            String decryptedValue = MyCryptUtil.decrypt(super.getValue ( key ));
            return decryptedValue;
        }
    
    }
    

    NOTE the above is psuedo-code, there would be different methods to override


    And your XML might look like this:

    <PreferenceScreen
            xmlns:android="http://schemas.android.com/apk/res/android">
    
        <PreferenceCategory
                android:title="@string/inline_preferences">
    
            <com.example.myprefs.ListPreferenceCrypt
                    android:key="listcrypt_preference"
                    android:title="@string/title_listcrypt_preference"
                    android:summary="@string/summary_listcrypt_preference" />
    
        </PreferenceCategory>
    
    </PreferenceScreen>
    

    EDIT

    Caveats/Decompiling

    As I thought about this more, I realized one of the caveats is that this method is not particularly difficult to bypass when decompiling an APK. This does give the full class names of overriden classes in the layouts (though that can be avoided by not using XML)

    However, I don’t think this is significantly less secure than sub-classing SharedPreferences. That too, is susceptible to decompiling. Ultimately, if you want stronger security, you should consider alternative storage methods. Perhaps OAuth or the AccountManager as suggested in your linked post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.