Record Class DkimConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.email.security.DkimConfig

public record DkimConfig(String domain, String selector, PrivateKey privateKey, Set<String> headersToSign) extends Record
DKIM Signing Configuration DKIM签名配置

Configuration for DKIM (DomainKeys Identified Mail) signing.

DKIM(域名密钥识别邮件)签名的配置。

Features | 主要功能:

  • RSA private key support - RSA私钥支持
  • Configurable headers to sign - 可配置签名邮件头
  • Domain and selector configuration - 域名和选择器配置

Usage Examples | 使用示例:

DkimConfig dkim = DkimConfig.load("example.com", "mail", Path.of("dkim-private.pem"));

EmailConfig config = EmailConfig.builder()
    .host("smtp.example.com")
    .dkim(dkim)
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DkimConfig

      public DkimConfig(String domain, String selector, PrivateKey privateKey, Set<String> headersToSign)
      Creates an instance of a DkimConfig record class.
      Parameters:
      domain - the value for the domain record component
      selector - the value for the selector record component
      privateKey - the value for the privateKey record component
      headersToSign - the value for the headersToSign record component
  • Method Details

    • load

      public static DkimConfig load(String domain, String selector, Path keyPath)
      Load DKIM configuration from key file 从密钥文件加载DKIM配置
      Parameters:
      domain - the domain name | 域名
      selector - the DKIM selector | DKIM选择器
      keyPath - the path to private key file (PEM format) | 私钥文件路径(PEM格式)
      Returns:
      the DKIM configuration | DKIM配置
    • load

      public static DkimConfig load(String domain, String selector, Path keyPath, Set<String> headersToSign)
      Load DKIM configuration with custom headers 使用自定义邮件头加载DKIM配置
      Parameters:
      domain - the domain name | 域名
      selector - the DKIM selector | DKIM选择器
      keyPath - the path to private key file | 私钥文件路径
      headersToSign - the headers to sign | 要签名的邮件头
      Returns:
      the DKIM configuration | DKIM配置
    • of

      public static DkimConfig of(String domain, String selector, PrivateKey privateKey)
      Create DKIM configuration with private key 使用私钥创建DKIM配置
      Parameters:
      domain - the domain name | 域名
      selector - the DKIM selector | DKIM选择器
      privateKey - the private key | 私钥
      Returns:
      the DKIM configuration | DKIM配置
    • of

      public static DkimConfig of(String domain, String selector, PrivateKey privateKey, Set<String> headersToSign)
      Create DKIM configuration with all parameters 使用所有参数创建DKIM配置
      Parameters:
      domain - the domain name | 域名
      selector - the DKIM selector | DKIM选择器
      privateKey - the private key | 私钥
      headersToSign - the headers to sign | 要签名的邮件头
      Returns:
      the DKIM configuration | DKIM配置
    • getDefaultHeadersToSign

      public static Set<String> getDefaultHeadersToSign()
      Get default headers to sign 获取默认签名邮件头
      Returns:
      the default headers | 默认邮件头
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • domain

      public String domain()
      Returns the value of the domain record component.
      Returns:
      the value of the domain record component
    • selector

      public String selector()
      Returns the value of the selector record component.
      Returns:
      the value of the selector record component
    • privateKey

      public PrivateKey privateKey()
      Returns the value of the privateKey record component.
      Returns:
      the value of the privateKey record component
    • headersToSign

      public Set<String> headersToSign()
      Returns the value of the headersToSign record component.
      Returns:
      the value of the headersToSign record component