我有一个使用 TLS 的 java 聊天应用程序,但是当我使用 Wireshark 捕获数据时,协议(protocol)列显示值“TCP”,为什么它不显示为“TLS”。我的代码出了什么问题?
CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(
this.getClass().getResourceAsStream("/"+"lib/ca.crt")
);
InputStream is=this.getClass().getResourceAsStream("/"+"lib/plainclient.jks");
KeyStore clientKeys = KeyStore.getInstance("JKS");
clientKeys.load(is,"xuanthinh".toCharArray());
KeyManagerFactory clientKeyManager = KeyManagerFactory.getInstance("SunX509");
clientKeyManager.init(clientKeys,"xuanthinh".toCharArray());
KeyStore ks = KeyStore.getInstance("JKS");
is=this.getClass().getResourceAsStream("/"+"lib/serverpub.jks");
ks.load(is,"xuanthinh".toCharArray());
TrustManagerFactory trustManager = TrustManagerFactory.getInstance("SunX509");
trustManager.init(ks);
//use keys to create SSLSoket
ssl = SSLContext.getInstance("TLS");
ssl.init(
clientKeyManager.getKeyManagers(), trustManager.getTrustManagers(),
SecureRandom.getInstance("SHA1PRNG")
);
最佳答案
它们是不同的协议(protocol),并且都在传输加密内容时使用。
阅读 OSI Model对于网络协议(protocol),因为这解释了每个协议(protocol)相对于彼此的位置。
TCP 是第 4 层(传输层)的一部分,而 TLS 是第 6 层(表示层)的一部分。
关于java - 如何在java中使用TLSv1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40998226/