Posts

Showing posts from April, 2022

SSLSocketFactory in Android

Image
Overview SSLSocketFactory is used to create secure sockets. Steps to follow First you have to create a key store. Open command prompt using Administrator login. Type " cd C:\Program Files\Java\jdk-14\bin ". Type the below command keytool -genkey -v -keystore my-key.keystore -alias my-key-alias-keyalg RSA -keysize 2048 -validity 10000 Follow the steps given in the screenshot: For - keyalg you can use RSA, DSA, EC to generate asymmetric key pair or use DES, 3DES to generate symmetric key pair. Then you have to generate a certificate Open command prompt using Administrator login. Type " cd C:\Program Files\Java\jdk-14\bin ". Type the below command keytool -certreq -alias "my-key-alias" -file mycertreq.csr -keystore my-key.keystore Follow the steps given in the screenshot. Note: The password , alias name , keystore name must be the same which you used while creating the keystore . An example of creating a subclass of SSLSocketFactory class TLSSocketFact

Connectivity in Android

Image
Connect to the network To perform network operations in your application, your manifest must include the following permissions: < uses-permission android :name ="android.permission.INTERNET" /> < uses-permission android :name ="android.permission.ACCESS_NETWORK_STATE" /> Note: Both the Internet and ACCESS_NETWORK_STATE permissions are normal permissions , which means they're granted at install time and don't need to be requested runtime . Best practices for secure network communication Minimize the amount of sensitive or personal user data that you transmit over the network. Send all network traffic from your app over SSL . Consider creating a network security configuration , which lets your app trust custom certificate authorities (CAs) or restrict the set of system CAs that it trusts for secure communication. Follow networking security tips Choose an HTTP client Most network-connected apps use HTTP to send and receive data. The Android pla

App data and files in Android

Image
Save data using SQLite Saving data to a database is ideal for repeating or structured data, such as contact information. Define a schema and contact Schema is a formal declaration of how the database is organized.  You should create a companion class, known as a contract class , which explicitly specifies the layout of your schema in a systematic and self-documenting way. A contract class is a container for constants that define names for URIs, tables and columns. The contract class allows you to use the same constants across all the other classes in the same package. A good way to organize a contract class is to put definitions that are global to your whole database in the root level of the class. Then create an inner class for each table. Each inner class enumerates the corresponding table's columns. For complete implementation please click the header or check the e.g. public class DeviceContract { private DeviceContract () { } public static class DeviceEntry impl