Hutool Hutool
(opens new window)
🏡首页
📖指南
🎢最佳实践
💖支持
💡javaDoc (opens new window)
⏳更新记录 (opens new window)
  • 🍎gitee (opens new window)
  • 🍏github (opens new window)
(opens new window)
🏡首页
📖指南
🎢最佳实践
💖支持
💡javaDoc (opens new window)
⏳更新记录 (opens new window)
  • 🍎gitee (opens new window)
  • 🍏github (opens new window)
  • 快速入门

  • 核心(hutool-core)

    • AI(Hutool-ai)

    • 注解(annotation)

    • 数组(array)

    • JavaBean(bean)

    • 缓存(cache)

    • 类加载器(classloader)

    • 编码解码(codec)

    • 集合(collection)

    • 比较器(comparator)

    • 压缩(compress)

    • 类型转换(convert)

    • 数据(data)

    • 日期时间(date)

    • 异常(exception)

    • 函数(func)

    • IO流(io)

    • 语言特性(lang)

    • Map(map)

    • 数字数学(math)

    • 网络(net)

      • 网络
      • NetUtil
      • Ipv4Util
      • Ipv6Util
      • MacAddressUtil
      • KeyManagerUtil
      • SSL上下文工具-SSLContextUtil
        • 主要功能
        • 主要方法
          • getDefault()
          • createTrustAnySSLContext()
          • createTrustAnySSLContext(String protocol)
          • createSSLContext(String protocol, KeyManager keyManager, TrustManager trustManager)
          • createSSLContext(KeyStore keyStore, char[] password)
          • createSSLContext(KeyManager[] keyManagers, TrustManager[] trustManagers)
          • createSSLContext(String protocol, KeyManager[] keyManagers, TrustManager[] trustManagers)
        • 示例代码
          • 获取默认SSLContext
          • 创建信任所有证书的SSLContext
          • 从KeyStore创建SSLContext
          • 使用密钥管理器和信任管理器创建SSLContext
      • 信任管理器工具-TrustManagerUtil
      • URL构建器-UrlBuilder
      • URL协议工具-UrlProtocolUtil
      • URL查询工具-UrlQueryUtil
      • URL工具-UrlUtil
    • 对象池(pool)

    • 反射(reflect)

    • 正则(regex)

    • 服务提供(spi)

    • 聚合操作(stream)

    • 字符串文本(text)

    • 并发和线程(thread)

    • 树结构(tree)

    • 工具集合(util)

    • XML操作(xml)

  • 定时任务(hutool-cron)

  • 加密(hutool-crypto)

  • 数据库(hutool-db)

  • 扩展(hutool-extra)

  • HTTP(hutool-http)

  • 日志(hutool-log)

  • 配置文件(hutool-setting)

  • JSON(hutool-json)

  • Office办公(hutool-poi)

  • 套接字(hutool-socket)

  • GUI(hutool-swing)

  • 指南
  • 核心(hutool-core)
  • 网络(net)
Hutool
2026-01-23
目录

SSL上下文工具-SSLContextUtil

SSLContextUtil是Hutool中用于处理SSL(Secure Sockets Layer 安全套接字协议)中SSLContext的工具类,提供了多种创建和获取SSLContext的方法。

# 主要功能

  • 获取默认SSLContext
  • 创建信任所有证书的SSLContext
  • 使用不同参数组合创建SSLContext
  • 从KeyStore创建SSLContext

# 主要方法

# getDefault()

获取默认的SSLContext。

# createTrustAnySSLContext()

创建信任所有证书的SSLContext,使用默认TLS协议。

# createTrustAnySSLContext(String protocol)

创建信任所有证书的SSLContext,可指定SSL协议。

# createSSLContext(String protocol, KeyManager keyManager, TrustManager trustManager)

使用单个密钥管理器和信任管理器创建SSLContext。

# createSSLContext(KeyStore keyStore, char[] password)

从KeyStore创建SSLContext,同时使用KeyStore中的证书作为信任证书。

# createSSLContext(KeyManager[] keyManagers, TrustManager[] trustManagers)

使用密钥管理器数组和信任管理器数组创建SSLContext,使用默认TLS协议。

# createSSLContext(String protocol, KeyManager[] keyManagers, TrustManager[] trustManagers)

使用完整参数创建SSLContext,可指定协议、密钥管理器数组和信任管理器数组。

# 示例代码

# 获取默认SSLContext

SSLContext sslContext = SSLContextUtil.getDefault();

# 创建信任所有证书的SSLContext

// 使用默认TLS协议
SSLContext sslContext = SSLContextUtil.createTrustAnySSLContext();

// 指定协议
SSLContext sslContext = SSLContextUtil.createTrustAnySSLContext("TLSv1.2");

# 从KeyStore创建SSLContext

// 加载KeyStore
KeyStore keyStore = KeyStore.getInstance("JKS");
try (InputStream is = new FileInputStream("path/to/keystore.jks")) {
    keyStore.load(is, "password".toCharArray());
}

// 创建SSLContext
SSLContext sslContext = SSLContextUtil.createSSLContext(keyStore, "password".toCharArray());

# 使用密钥管理器和信任管理器创建SSLContext

// 创建密钥管理器
KeyManager[] keyManagers = KeyManagerUtil.createKeyManagers("path/to/keystore.jks", "keystorePassword".toCharArray());

// 创建信任管理器
TrustManager[] trustManagers = TrustManagerUtil.createTrustManagers("path/to/truststore.jks", "truststorePassword".toCharArray());

// 创建SSLContext
SSLContext sslContext = SSLContextUtil.createSSLContext("TLS", keyManagers, trustManagers);
KeyManagerUtil
信任管理器工具-TrustManagerUtil

← KeyManagerUtil 信任管理器工具-TrustManagerUtil→

Theme by Vdoing | Copyright © 2025-2026 Hutool | Apache-2.0
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式