How to Implement TLSv1.3 in Applications: Difference between revisions

From wizarPOS
No edit summary
Line 7: Line 7:
Snippet Code:
Snippet Code:
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
  Provider conscrypt = Conscrypt.newProvider();
    /**
  // Add as provider
    * dependencies implementation 'org.conscrypt:conscrypt-android:2.5.2'
  Security.insertProviderAt(conscrypt, 1);
    * @param url
  SSLContext context = SSLContext.getInstance("TLSv1.3");
    */
 
    private void tlsv13(String url) {
  context.init(null/*keyManagers*/, null /*new CtsTrustManager[] {trustManager}*/, null);
        Provider conscrypt = Conscrypt.newProvider();
  SSLSocketFactory factory = context.getSocketFactory();
        try {
  URL sslURL = new URL("https://www.vpslala.com/");
            SSLContext context = SSLContext.getInstance("TLSv1.3",conscrypt);
  HttpsURLConnection con = (HttpsURLConnection) sslURL.openConnection();
            context.init(null/*keyManagers*/, null /*new CtsTrustManager[] {trustManager}*/, null);
  con.setSSLSocketFactory(factory);
            SSLSocketFactory factory = context.getSocketFactory();
  Log.d("SQLTest", "SQLTestTLS13. "+con.getResponseMessage());
            URL sslURL = new URL(url);
            HttpsURLConnection con = (HttpsURLConnection) sslURL.openConnection();
            con.setSSLSocketFactory(factory);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
</syntaxhighlight >
</syntaxhighlight >

Revision as of 07:03, 30 June 2022

References

GitHub project

Resouces

Sample

Snippet Code:

    /**
     * dependencies implementation 'org.conscrypt:conscrypt-android:2.5.2'
     * @param url
     */
    private void tlsv13(String url) {
        Provider conscrypt = Conscrypt.newProvider();
        try {
            SSLContext context = SSLContext.getInstance("TLSv1.3",conscrypt);
            context.init(null/*keyManagers*/, null /*new CtsTrustManager[] {trustManager}*/, null);
            SSLSocketFactory factory = context.getSocketFactory();
            URL sslURL = new URL(url);
            HttpsURLConnection con = (HttpsURLConnection) sslURL.openConnection();
            con.setSSLSocketFactory(factory);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }