java der 解码_X.509证书的 Base64 和 DER 编码

博客介绍了X.509证书的PEM和DER两种编码格式,Java平台常用DER格式,WebSphere应用服务器可处理两种格式。还阐述了处理Java密钥库时证书和密钥文件转换的必要性,并详细说明了使用openssl和java keytool工具进行DER与PEM证书格式转换的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Certificates

X.509-Certificates are encoded in a Base64 ascii format called PEM or in a binary formed called DER.

The PEM format is the most used format. PEM certificates typically have file extentions such as

.pem

and

.crt

,

.cer

.

A DER formatted certificate contains all the same information as an PEM certificate, however it's encoded in a binary way. DER certificates typically have file extentions such as

.der

and

.cer

.

Java Platforms often use the binary DER Format.

However WebSphere Application Server handls both formats. WebSphere stores its certificates in a p12-File located in the config folder. p12 (PKCS#12) files are certificate stores which can contain  certificates with private and public keys. p12 files are usually protected with a password.

When dealing with Java Keystores (JKS) converting of certificates and key files is necessary.

Converting Certificate formats

It is possible to convert this two certificate formats using tools like the java keytool or openssl.

Converting with openssl

Converting certificates with openssl is straight forward.

Converting from DER to PEM:

openssl x509 -in

-inform PEM

-out  -outform DER

Converting from PEM to DER:

openssl x509 -in

-inform DER

-out  -outform PEM

Converting with java keytool

The java keytool does not allow to directly convert certificates. However when creating a java keystore (JKS) first, certificates can be imported and exported in different formats.

Generate a keystore and delete the mandatory certificate in it:

When generating the keystore with the first command keytool demands several inputs for the mandatory certificate it will generate.We do not need this certificate for convertions and we will delete it afterwards -  so you could type in some foo. I will use the aliastest

in this example.

keytool -genkey -alias test -keystore

keytool -delete -alias test -keystore

Converting from DER to PEM:

keytool -import -trustcacerts -aliastest -file

-keystore

test.keystore

keytool -exportcert -alias test

-file

-rfc

-keystore test.keystore

Converting from PEM to DER:

keytool -import -trustcacerts -aliastest -file

-keystore

test.keystore

keytool -exportcert -alias test

-file

-keystore test.keystore

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值