Difference between trustStore and keyStore in Java - SSL

 
trustStore vs keyStore in Java
trustStore and keyStore are used in context of setting up SSL connection in Java application between client and server. TrustStore and keyStore are very much similar in terms of construct and structure as both are managed by keytoolcommand and represented by KeyStore programatically but they often confused Java programmer both beginners and intermediate alike. Only difference between trustStore and keyStore is what they store and there purpose. In SSL handshake purpose of trustStore is to verify credentials and purpose of keyStore is to provide credential. keyStore in Java stores private key and certificates corresponding to there public keys and require if you are SSL Server or SSL requires client authentication. TrustStore stores certificates from third party, your Java application communicate or certificates signed by CA(certificate authorities like Verisign, Thawte, Geotrust or GoDaddy) which can be used to identify third party. This is second article on setting up SSL on Java program, In last post we have seen How to import SSL certificates into trustStore and keyStore and In this Java article we will some differences between keystore and truststore in Java, which will help to understand this concept better.
 
 

Difference between trustStore and keyStore in Java

Here is the list of most common difference between keyStore and trustStore. I have already mentioned key difference in first paragraph which is related to purpose of keyStore and trustStore, which we will see here is little more detail.
 
1)First and major difference between trustStore and keyStore is that trustStore is used by TrustManager and keyStore is used by KeyManager class in Java. KeyManager and TrustManager performs different job in Java, TrustManager determines whether remote connection should be trusted or not i.e. whether remote party is who it claims to and KeyManager decides which authentication credentials should be sent to the remote host for authentication during SSL handshake. if you are an SSL Server you will use private key during key exchange algorithm and send certificates corresponding to your public keys to client, this certificate is acquired from keyStore. On SSL client side, if its written in Java, it will use certificates stored in trustStore to verify identity of Server. SSL certificates are most commonly comes as .cer file which is added into keyStore or trustStore by using any key management utility e.g. keytool. See my post How to add certificates into trustStore for step by step guide on adding certificates into keyStore or trustStore in Java.
 
2) Another difference between trustStore and keyStore in rather simple terms is that keyStore contains private keys and required only if you are running a Server in SSL connection or you have enabled client authentication on server side. On the other hand trustStore stores public key or certificates from CA (Certificate Authorities) which is used to trust remote party or SSL connection.
 
3)One more difference between trustStore vs KeyStore is that we use -Djavax.net.ssl.keyStore to specify path for keyStore and -Djavax.net.ssl.trustStore to specify path for trustStore in Java.
 
4) Another difference between trustStore and keyStore is that, If you store your personal certificate along with signer certificate in trustStore,  you can use same file as both trustStore and keyStore. By the way its good idea to separate personal certificate and signer certificates in keyStore and trustStore for better management.
 
5) One more API level difference between keyStore and trustStore is that  password of keyStore is provided using -Djavax.net.ssl.keyStorePassword and password of trustStore is provided using -Djavax.net.ssl.trustStorePassword.
 
That’s all on difference between trustStore and keyStore in Java. You can still use same file as trustStore and keyStore in Java to avoid maintaining two separate files, but its good idea to segregate public keys and private keys in two different files, its more verbose and self explanatory that which one holds CA certificates to trust server and which contains client's private keys.
 
总之,keyStore是用于存放自己keytool产生的key(public/private) (浏览器是否相信server, public key经过CA签名用于商业SSL), truststore用于存放第三方提供的经过CA认证的public key(用于server是否相信第三方连接)

Read more: https://javarevisited.blogspot.com/2012/09/difference-between-truststore-vs-keyStore-Java-SSL.html#ixzz5i1OTp1X1

Difference between trustStore and keyStore in Java - SSL的更多相关文章

  1. java ssl https 连接详解 生成证书

    我们先来了解一下什么理HTTPS 1. HTTPS概念 1)简介 HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全 ...

  2. java ssl https 连接详解 生成证书 tomcat keystone

    java ssl https 连接详解 生成证书 我们先来了解一下什么理HTTPS 1. HTTPS概念 1)简介 HTTPS(全称:Hypertext Transfer Protocol over ...

  3. Different types of keystore in Java Overview

    Different types of keystore in Java JKS DKS JCEKS PKCS12 PKCS11 http://www.pixelstech.net/article/14 ...

  4. Java SSL/TLS Socket实现

    通信端无需向对方证明自己的身份,则称该端处于"客户模式",否则称其处于"服务器模式",无论是客户端还是服务器端,都可处于"客户模式"或者&q ...

  5. Difference between LinkedList vs ArrayList in Java

    source-url LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynami ...

  6. 配置Java SSL 访问网站证书

    最近在开发 Java 访问 Azure ServiceBus 时遇到SSL证书问题,导致JAVA报错,不能正常访问,报错信息如下: javax.net.ssl.SSLException: Connec ...

  7. java ssl 连接AD域

    1.安装证书服务和IIS服务,不需要启动asp.(其会在c盘生成一个crt文件)2.获取crt证书文件 windows 2003:文件位于系统盘根目录 windows 2008: 文件位于C:\Win ...

  8. https Java SSL Exception protocol_version

    在java代码中,使用HttpClient爬取https页面时,遇到了这个bug:javax.net.ssl.SSLException: Received fatal alert: protocol_ ...

  9. Java ssl认证记录

    听到有人在用,所以自己随便搜了搜试了下,这里就是简单记录 就是操作了一遍这篇博文 https://blog.csdn.net/a495614205/article/details/12648939 i ...

随机推荐

  1. React 组件间通信 总结

    组件间通信 5.1.1. 方式一: 通过props传递 1)         共同的数据放在父组件上, 特有的数据放在自己组件内部(state) 2)         通过props可以传递一般数据和 ...

  2. Appium - adb命令操作

    1.Android 调试桥adb ( Android Debug Bridge)是一个通用命令行工具,其允许您与模拟器实例或连接的 Android 设备进行通信.它可为各种设备操作提供便利,如安装和调 ...

  3. POJ1704 Georgia and Bob 题解

    阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...

  4. Deepin 20.2.2 /UOS 20.2 添加ppa源

    由于 工作需要,需要通过PPA安装一些优质的软件包,但是 Deepin 默认不支持PPA源 解决方法 由于Deepin/Uos系统默认是没有安装PPA的那么我们得先安装PPA来支持"add- ...

  5. dotnet部署出现Failed to load the dll from [ ... hostfxr.dll], HRESULT: 0x80070057

    起因 最近看到.net core 3支持wpf了,尝试一下(如果可行,会特别利于脱离.net运行时) dotnet new wpf dotnet publish -c Release -r win-x ...

  6. C++ 定义默认值void locals_index(int reg, int offset = 1);

    看jvm源码的时候怎么也看不懂,来回看了几次了就是关于iload 6 指令的解析 def(Bytecodes::_lload , ubcp|____|____|____, vtos, ltos, ll ...

  7. Java文件I/O简单介绍

    目录 一.File类 1.1 构造方法 1.2 常用方法 1.3 例子 二.基础I/O:字节流.字符流 2.1 字节流 2.1.1 字节输出流 OutputStream 2.1.2 FileOutpu ...

  8. ifix中嵌入3d模型初探(一)

    在ifix项目中插入3d模型,是当前工控上位机的一个发展趋势,故而我也来尝尝鲜.利用现有条件,初步打算完成一个工厂俯视3d全景. 基本思路:利用webbrowser+3dmax+three.js来嵌入 ...

  9. webrtc编译

    webrtc编译 最近研究 libmediasoupclient,而 libmediasoupclient 又依赖 libwebrtc,所以首先就想着先在windows上编译一个webrtc的库,先是 ...

  10. centos ansible常用命令

    ansible在日常运维中经常使用,特别是批量执行多台服务器的时候,有效减小重复的操作成本,以下从安装到使用仅讲解工作中常用的几种方式,模块很多功能很强大,但不做全面讨论. ansible安装 在ce ...