public class PemKeys extends Object
PEM一般为文本格式,以 -----BEGIN... 开头,以 -----END... 结尾,中间的内容是 BASE64 编码。
这种格式可以保存证书和私钥,有时我们也把PEM格式的私钥的后缀改为 .key 以区别证书与私钥。
| 构造器和说明 |
|---|
PemKeys() |
| 限定符和类型 | 方法和说明 |
|---|---|
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)
已过时。
|
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) throws GeneralSecurityException, IOException
pemStream - pem流PrivateKeyGeneralSecurityExceptionIOExceptionpublic static PublicKey readPemPublicKey(InputStream pemStream) throws GeneralSecurityException, IOException
pemStream - pem流PublicKeyGeneralSecurityExceptionIOExceptionpublic static Key readPemKey(InputStream keyStream) throws GeneralSecurityException, IOException
keyStream - pem流Key,null表示无法识别的密钥类型GeneralSecurityExceptionIOExceptionpublic static byte[] readPem(InputStream keyStream) throws IOException
keyStream - pem流IOExceptionpublic static org.bouncycastle.util.io.pem.PemObject readPemObject(InputStream keyStream) throws IOException
keyStream - pem流PemObjectIOExceptionpublic static org.bouncycastle.util.io.pem.PemObject readPemObject(Reader reader) throws IOException
reader - pem ReaderPemObjectIOException@Deprecated public static PrivateKey readSm2PemPrivateKey(InputStream keyStream) throws GeneralSecurityException, IOException
readPemPrivateKey(InputStream)keyStream - 私钥pem流PrivateKeyGeneralSecurityExceptionIOExceptionpublic static String toPem(String type, byte[] content) throws IOException
type - 密钥类型(私钥、公钥、证书)content - 密钥内容IOExceptionpublic static void writePemObject(String type, byte[] content, OutputStream keyStream) throws IOException
type - 密钥类型(私钥、公钥、证书)content - 密钥内容,需为PKCS#1格式keyStream - pem流IOExceptionpublic static void writePemObject(String type, byte[] content, Writer writer) throws IOException
type - 密钥类型(私钥、公钥、证书)content - 密钥内容,需为PKCS#1或PKCS#8格式writer - pemWriterIOExceptionpublic static void writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject,
OutputStream keyStream)
throws IOException
pemObject - pem对象,包括密钥和密钥类型等信息keyStream - pem流IOExceptionpublic static void writePemObject(org.bouncycastle.util.io.pem.PemObjectGenerator pemObject,
Writer writer)
throws IOException
pemObject - pem对象,包括密钥和密钥类型等信息writer - pemWriterIOExceptionCopyright © 2024 fossc. All rights reserved.