Example usage for java.security.cert Certificate hashCode

List of usage examples for java.security.cert Certificate hashCode

Introduction

In this page you can find the example usage for java.security.cert Certificate hashCode.

Prototype

public int hashCode() 

Source Link

Document

Returns a hashcode value for this certificate from its encoded form.

Usage

From source file:Main.java

public static void addCertToKnownServersStore(Certificate cert, Context context)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
    KeyStore knownServers = getKnownServersStore(context);
    knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
    FileOutputStream fos = null;//from   w  w  w  . j  a  v  a  2 s.  co m
    try {
        fos = context.openFileOutput(LOCAL_TRUSTSTORE_FILENAME, Context.MODE_PRIVATE);
        knownServers.store(fos, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());
    } finally {
        fos.close();
    }
}

From source file:com.cerema.cloud2.lib.common.network.NetworkUtils.java

public static boolean isCertInKnownServersStore(Certificate cert, Context context)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {

    KeyStore knownServers = getKnownServersStore(context);
    Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
            + Boolean.toString(knownServers.isCertificateEntry(Integer.toString(cert.hashCode()))));
    return knownServers.isCertificateEntry(Integer.toString(cert.hashCode()));
}

From source file:com.cerema.cloud2.lib.common.network.NetworkUtils.java

public static void addCertToKnownServersStore(Certificate cert, Context context)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {

    KeyStore knownServers = getKnownServersStore(context);
    knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
    FileOutputStream fos = null;/*from   www . ja  va2 s.c om*/
    try {
        fos = context.openFileOutput(LOCAL_TRUSTSTORE_FILENAME, Context.MODE_PRIVATE);
        knownServers.store(fos, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());
    } finally {
        fos.close();
    }
}

From source file:com.owncloud.android.lib.common.network.NetworkUtils.java

public static String addCertToKnownServersStore(Certificate cert, Context context)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {

    KeyStore knownServers = getKnownServersStore(context);
    String alias = Integer.toString(cert.hashCode());
    knownServers.setCertificateEntry(alias, cert);
    FileOutputStream fos = null;// www  . j  a  va  2 s  . c om
    try {
        fos = context.openFileOutput(LOCAL_TRUSTSTORE_FILENAME, Context.MODE_PRIVATE);
        knownServers.store(fos, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());
    } finally {
        fos.close();
    }
    return alias;
}

From source file:com.ct855.util.HttpsClientUtil.java

private void print_https_cert(HttpsURLConnection con) {

    if (con != null) {

        try {/*from w w  w .  ja v  a2  s.com*/

            System.out.println("Response Code : " + con.getResponseCode());
            System.out.println("Cipher Suite : " + con.getCipherSuite());
            System.out.println("\n");

            Certificate[] certs = con.getServerCertificates();
            for (Certificate cert : certs) {
                System.out.println("Cert Type : " + cert.getType());
                System.out.println("Cert Hash Code : " + cert.hashCode());
                System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
                System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
                System.out.println("\n");
            }

        } catch (SSLPeerUnverifiedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

From source file:org.hyperledger.fabric.sdk.security.CryptoPrimitives.java

private void addCACertificateToTrustStore(Certificate certificate)
        throws InvalidArgumentException, CryptoException {

    String alias;/* w w  w .  ja  va  2s. co m*/
    if (certificate instanceof X509Certificate) {
        alias = ((X509Certificate) certificate).getSerialNumber().toString();
    } else { // not likely ...
        alias = Integer.toString(certificate.hashCode());
    }
    addCACertificateToTrustStore(certificate, alias);
}