Class PemCodec
java.lang.Object
cloud.opencode.base.crypto.codec.PemCodec
PEM format encoding and decoding utility - Handle PEM encoded keys and certificates
PEM 格式编解码工具类 - 处理 PEM 编码的密钥和证书
Features | 主要功能:
- PEM format encoding and decoding - PEM 格式编码和解码
- Certificate and key format support - 证书和密钥格式支持
Usage Examples | 使用示例:
String pem = PemCodec.encode("CERTIFICATE", derBytes);
byte[] der = PemCodec.decode(pem);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Decode PEM formatted string to bytes 将 PEM 格式字符串解码为字节static byte[]decodeCertificate(String pem) Decode PEM formatted certificate to bytes 将 PEM 格式的证书解码为字节static byte[]decodePrivateKey(String pem) Decode PEM formatted private key to bytes 将 PEM 格式的私钥解码为字节static byte[]decodePublicKey(String pem) Decode PEM formatted public key to bytes 将 PEM 格式的公钥解码为字节static StringEncode data to PEM format with custom type 使用自定义类型将数据编码为 PEM 格式static StringencodeCertificate(byte[] cert) Encode certificate bytes to PEM format 将证书字节编码为 PEM 格式static StringencodePrivateKey(byte[] key) Encode private key bytes to PEM format 将私钥字节编码为 PEM 格式static StringencodePublicKey(byte[] key) Encode public key bytes to PEM format 将公钥字节编码为 PEM 格式static StringGet PEM type identifier from PEM string 从 PEM 字符串获取类型标识符
-
Method Details
-
encodePublicKey
Encode public key bytes to PEM format 将公钥字节编码为 PEM 格式- Parameters:
key- public key bytes- Returns:
- PEM formatted string
- Throws:
NullPointerException- if key is null
-
decodePublicKey
Decode PEM formatted public key to bytes 将 PEM 格式的公钥解码为字节- Parameters:
pem- PEM formatted public key- Returns:
- decoded key bytes
- Throws:
NullPointerException- if pem is nullIllegalArgumentException- if pem is not valid format
-
encodePrivateKey
Encode private key bytes to PEM format 将私钥字节编码为 PEM 格式- Parameters:
key- private key bytes- Returns:
- PEM formatted string
- Throws:
NullPointerException- if key is null
-
decodePrivateKey
Decode PEM formatted private key to bytes 将 PEM 格式的私钥解码为字节- Parameters:
pem- PEM formatted private key- Returns:
- decoded key bytes
- Throws:
NullPointerException- if pem is nullIllegalArgumentException- if pem is not valid format
-
encodeCertificate
Encode certificate bytes to PEM format 将证书字节编码为 PEM 格式- Parameters:
cert- certificate bytes- Returns:
- PEM formatted string
- Throws:
NullPointerException- if cert is null
-
decodeCertificate
Decode PEM formatted certificate to bytes 将 PEM 格式的证书解码为字节- Parameters:
pem- PEM formatted certificate- Returns:
- decoded certificate bytes
- Throws:
NullPointerException- if pem is nullIllegalArgumentException- if pem is not valid format
-
encode
Encode data to PEM format with custom type 使用自定义类型将数据编码为 PEM 格式- Parameters:
type- PEM type identifier (e.g., "RSA PRIVATE KEY")data- data bytes to encode- Returns:
- PEM formatted string
- Throws:
NullPointerException- if type or data is nullIllegalArgumentException- if type is empty
-
decode
Decode PEM formatted string to bytes 将 PEM 格式字符串解码为字节- Parameters:
pem- PEM formatted string- Returns:
- decoded bytes
- Throws:
NullPointerException- if pem is nullIllegalArgumentException- if pem is not valid format
-
getType
Get PEM type identifier from PEM string 从 PEM 字符串获取类型标识符- Parameters:
pem- PEM formatted string- Returns:
- PEM type identifier
- Throws:
NullPointerException- if pem is nullIllegalArgumentException- if pem is not valid format
-