Code example for SecretKey

Methods: getEncoded

0
KeyGenerator kgen = KeyGenerator.getInstance("AES");  
	    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");  
	    kgen.init(m_nKeyLenBit, sr);  
	    SecretKey skey = kgen.generateKey();  
	    m_dbKeyData = skey.getEncoded();
	    Logger.I(TAG, "New key is generated");
	    if(DEBUG)
	        Logger.I(TAG, "Key: " + dumpKey(m_dbKeyData));
	} 
 
    private void writeKeyToStorage() 
    { 
        SharedPreferences settings =  ContextFactory.getContext().getSharedPreferences(m_strPrefName, Context.MODE_PRIVATE);		
        SharedPreferences.Editor editor = settings.edit();
        String strKey = Base64.encodeToString(m_dbKeyData, false);//, Base64.DEFAULT);
         
        editor.putString(m_strDBPartition, strKey );
        if (editor.commit()) {
            Logger.I(TAG, "Key is successfully saved to Shared Preferences");
        } else {