Class PemClasspathReaderAndWriter

java.lang.Object
io.github.xezzon.zeroweb.core.crypto.PemClasspathReaderAndWriter
All Implemented Interfaces:
ASN1PrivateKeyReader, ASN1PrivateKeyWriter, ASN1PublicKeyReader, ASN1PublicKeyWriter

public class PemClasspathReaderAndWriter extends Object implements ASN1PublicKeyReader, ASN1PrivateKeyReader, ASN1PublicKeyWriter, ASN1PrivateKeyWriter
PemClasspathReaderAndWriter 提供了从classpath中读写PEM格式的公钥和私钥文件的功能。 它实现了 ASN1PublicKeyReader, ASN1PrivateKeyReader, ASN1PublicKeyWriter, ASN1PrivateKeyWriter 接口,从而支持对密钥的读取和写入操作。
Author:
xezzon
  • Field Details

    • FILE_SUFFIX

      public static final String FILE_SUFFIX
      PEM文件的默认后缀名,值为 ".pem"。
      See Also:
    • PUBLIC_KEY_FILE_SUFFIX

      public static final String PUBLIC_KEY_FILE_SUFFIX
      公钥PEM文件后缀名,值为 ".public.pem"。
      See Also:
    • PRIVATE_KEY_FILE_SUFFIX

      public static final String PRIVATE_KEY_FILE_SUFFIX
      私钥PEM文件后缀名,值为 ".secret.pem"。
      See Also:
    • PEM_PUBLIC_KEY_HEADER

      public static final String PEM_PUBLIC_KEY_HEADER
      PEM文件中公钥块的默认头尾描述符,值为 "PUBLIC KEY"。
      See Also:
    • PEM_PRIVATE_KEY_HEADER

      public static final String PEM_PRIVATE_KEY_HEADER
      PEM文件中私钥块的默认头尾描述符,值为 "PRIVATE KEY"。
      See Also:
  • Constructor Details

    • PemClasspathReaderAndWriter

      public PemClasspathReaderAndWriter(String name)
      构造一个新的 PemClasspathReaderAndWriter 实例。
      Parameters:
      name - PEM文件的逻辑名称,例如 "my-app-key"。
  • Method Details

    • readPublicKey

      public Object readPublicKey() throws IOException
      从classpath的PEM文件中读取公钥。 文件名格式为:${name}.public.pem
      Specified by:
      readPublicKey in interface ASN1PublicKeyReader
      Returns:
      ASN.1形式的公钥对象。
      Throws:
      IOException - 如果读取文件时发生I/O错误。
    • readPrivateKey

      public Object readPrivateKey() throws IOException
      从classpath的PEM文件中读取私钥。 文件名格式为:${name}.secret.pem
      Specified by:
      readPrivateKey in interface ASN1PrivateKeyReader
      Returns:
      ASN.1形式的私钥对象。
      Throws:
      IOException - 如果读取文件时发生I/O错误。
    • writePublicKey

      public void writePublicKey(byte[] publicKey) throws IOException
      向classpath的PEM文件中写入公钥。 文件名格式为:${name}.public.pem
      Specified by:
      writePublicKey in interface ASN1PublicKeyWriter
      Parameters:
      publicKey - 待写入的公钥字节数组。
      Throws:
      IOException - 如果写入文件时发生I/O错误。
    • writePrivateKey

      public void writePrivateKey(byte[] privateKey) throws IOException
      向classpath的PEM文件中写入私钥。 文件名格式为:${name}.secret.pem
      Specified by:
      writePrivateKey in interface ASN1PrivateKeyWriter
      Parameters:
      privateKey - 待写入的私钥字节数组。
      Throws:
      IOException - 如果写入文件时发生I/O错误。