【发布时间】:2014-12-20 03:54:17
【问题描述】:
java 8 默认提供程序支持“TLS_RSA_WITH_AES_128_CBC_SHA256”密码套件。参考 - https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJSSEProvider.
我也有以下程序来验证这一点。 但是当我尝试获取相同算法的密码时,它会出错。
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
public class CipherSuitesInfoGenerator {
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException {
SSLContext context = SSLContext.getDefault();
SSLSocketFactory sf = context.getSocketFactory();
String[] cipherSuites = sf.getSupportedCipherSuites();
String cipherName = "TLS_RSA_WITH_AES_128_CBC_SHA256";
for (String s : cipherSuites) {
if (s.equals(cipherName)) {
System.out.println(cipherName + " is supported");
try {
Cipher cipher = Cipher.getInstance(cipherName);
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;
}
}
}
}
输出是:
TLS_RSA_WITH_AES_128_CBC_SHA256 is supported
Cannot find any provider supporting TLS_RSA_WITH_AES_128_CBC_SHA256
【问题讨论】:
-
这可能是一个愚蠢的问题,但你确定你在 Java 8 上运行你的代码吗?
-
是的。我相信。我认为这个程序按预期工作。但现在它给出了错误。我不知道开发环境是否发生了变化。我已按原样复制粘贴的代码和输出。
-
密码套件!=密码。它们不是一回事。
标签: java ssl encryption java-8