4

I want to save some of my sensitive data (string) in keyStore. I found that keyStore only accepts secretKey objects. But, I'm not able to store it and and retreive it later using keyChain callback by using the alias name of the secretKey

Any help will be appreciated..!

Rolbin
  • 133
  • 13
  • Did you find any solution to your question? I have same requirement. – LoveForDroid Apr 21 '17 at 19:45
  • @LoveForDroid You have to store the key into the keystore and write the keystore into a file. Later you can load back the keystore from the file. Retrieving the key via keychain require user selection. – Rolbin Apr 25 '17 at 10:32

2 Answers2

0

I think you are looking something like MD5. An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output. MD5 hashes are commonly used with smaller strings when storing passwords, credit card numbers or other sensitive data in databases such as the popular MySQL. This tool provides a quick and easy way to encode an MD5 hash from a simple string of up to 256 characters in length.

MD5 hashes are also used to ensure the data integrity of files. Because the MD5 hash algorithm always produces the same output for the same given input, users can compare a hash of the source file with a newly created hash of the destination file to check that it is intact and unmodified.

Hashing String with MD5:

public class JavaMD5Hash {

public static void main(String[] args) {

        String password = "MyPassword123";

        System.out.println("MD5 in hex: " + md5(password));


        System.out.println("MD5 in hex: " + md5(null));
        //= d41d8cd98f00b204e9800998ecf8427e


        System.out.println("MD5 in hex: " 
            + md5("The quick brown fox jumps over the lazy dog"));
        //= 9e107d9d372bb6826bd81d3542a419d6
}


public static String md5(String input) {

    String md5 = null;

    if(null == input) return null;

    try {

    //Create MessageDigest object for MD5
    MessageDigest digest = MessageDigest.getInstance("MD5");

    //Update input string in message digest
    digest.update(input.getBytes(), 0, input.length());

    //Converts message digest value in base 16 (hex) 
    md5 = new BigInteger(1, digest.digest()).toString(16);

    } catch (NoSuchAlgorithmException e) {

        e.printStackTrace();
    }
    return md5;
}

}

referance : http://viralpatel.net/blogs/java-md5-hashing-salting-password/

https://www.mkyong.com/java/java-md5-hashing-example/

http://www.asjava.com/core-java/java-md5-example/

-2

you can use shared preferance which is very easy to handle also.

https://developer.android.com/training/basics/data-storage/shared-preferences.html

Android Shared preferences example

Community
  • 1
  • 1
  • 3
    I have already mentioned that it's some sensitive data that i want to store. Shared preference is not something i want :) – Rolbin Jul 20 '16 at 11:26
  • what kind of sensitive data you are using? like password? You can use "Sqlite library" for saving data also . But if you want something like password , you can convert the string to md5 & later reverse back to string in the app , so, this way, you only store the converted md5 value to database only. do you want to store the data permamently or just while the application is running? –  Jul 20 '16 at 13:54
  • Ya, something like a password and I want to store it permanently. If I store it in database an attacker can easily retrieve it and convert it back and use. – Rolbin Jul 21 '16 at 05:26