public class PemUtil extends Object
PEM一般为文本格式,以 -----BEGIN... 开头,以 -----END... 结尾,中间的内容是 BASE64 编码。
这种格式可以保存证书和私钥,有时我们也把PEM格式的私钥的后缀改为 .key 以区别证书与私钥。
Constructor and Description |
---|
PemUtil() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
readPem(InputStream keyStream)
从pem流中读取公钥或私钥
|
static Key |
readPemKey(InputStream keyStream)
|
static org.bouncycastle.util.io.pem.PemObject |
readPemObject(InputStream keyStream)
读取pem文件中的信息,包括类型、头信息和密钥内容
|
static org.bouncycastle.util.io.pem.PemObject |
readPemObject(Reader reader)
读取pem文件中的信息,包括类型、头信息和密钥内容
|
static PrivateKey |
readPemPrivateKey(InputStream pemStream)
读取PEM格式的私钥,支持PKCS#8和PKCS#1的ECC格式
|
static PublicKey |
readPemPublicKey(InputStream pemStream)
读取PEM格式的公钥
|
static PrivateKey |
readSm2PemPrivateKey(InputStream keyStream)
Deprecated.
|
static String |
toPem(String type,
byte[] content)
将私钥或公钥转换为PEM格式的字符串
|
static void |
writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject,
OutputStream keyStream)
写出pem密钥(私钥、公钥、证书)
|
static void |
writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject,
Writer writer)
写出pem密钥(私钥、公钥、证书)
|
static void |
writePemObject(String type,
byte[] content,
OutputStream keyStream)
写出pem密钥(私钥、公钥、证书)
|
static void |
writePemObject(String type,
byte[] content,
Writer writer)
写出pem密钥(私钥、公钥、证书)
|
public static PrivateKey readPemPrivateKey(InputStream pemStream)
pemStream
- pem流PrivateKey
public static PublicKey readPemPublicKey(InputStream pemStream)
pemStream
- pem流PublicKey
public static Key readPemKey(InputStream keyStream)
keyStream
- pem流Key
,null表示无法识别的密钥类型public static byte[] readPem(InputStream keyStream)
keyStream
- pem流public static org.bouncycastle.util.io.pem.PemObject readPemObject(InputStream keyStream)
keyStream
- pem流PemObject
public static org.bouncycastle.util.io.pem.PemObject readPemObject(Reader reader)
reader
- pem ReaderPemObject
@Deprecated public static PrivateKey readSm2PemPrivateKey(InputStream keyStream)
readPemPrivateKey(InputStream)
keyStream
- 私钥pem流PrivateKey
public static String toPem(String type, byte[] content)
type
- 密钥类型(私钥、公钥、证书)content
- 密钥内容public static void writePemObject(String type, byte[] content, OutputStream keyStream)
type
- 密钥类型(私钥、公钥、证书)content
- 密钥内容,需为PKCS#1格式keyStream
- pem流public static void writePemObject(String type, byte[] content, Writer writer)
type
- 密钥类型(私钥、公钥、证书)content
- 密钥内容,需为PKCS#1或PKCS#8格式writer
- pemWriterpublic static void writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject, OutputStream keyStream)
pemObject
- pem对象,包括密钥和密钥类型等信息keyStream
- pem流public static void writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject, Writer writer)
pemObject
- pem对象,包括密钥和密钥类型等信息writer
- pemWriterCopyright © 2024. All rights reserved.