1.通过openssl查看
[root@ahdjg ~]#openssl req -in cerseq.csr -text #cerseq.csr存放的是p10的base64格式数据
unable to load X509 request
140239849273232:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:707:Expecting: CERTIFICATE REQUEST
但是这种方式报错,具体不知道,哪里的问题。选择以代码的方式来查看p10内容,是正常的。
2.通过Java代码查看p10内容
public static void main(String[] args) {getPublicKeyByP10();}public static void getPublicKeyByP10() {try {//模拟读取PKCS10格式文件得到的数据,为防泄密这里的p10是假数据String p10str ="MIIBHDCBxAIBATBiMRwwGgYDVQQ0DxPmipXmoIfmtYvor5XljZXkvY0xMRQwEgYDVQQLDAt6aGFvdG91YmlhbzENMAsGA1UECwwEVEJEVzEQMA4GA1UECgwHU0lOT1BFQzELMAkGA1UEBgwCQ04wWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAASDqxbIMK7tJihJy3OFXvM2l4wr6AxRtMYAx6s6rlQ2pKPchdBXKvg0vF9/X+cfdoHvzRQiYLZDUW6WqhlzyK0CoAAwCgYIKoEcz1UBg3UDRwAw0AIgToHccXHyihKj3V/xudKGlQyc6yxdFvl9lpbJxTcdBFxxIH7nbj7gQDn3gzVkVVQAcWuhc+t7JCbW2MNa6pwx1SSw";//p10str = CertHelper.removeTagP10(p10str); -- 这个方法是为了把开始和结束标签去掉//创建证书请求PKCS10CertificationRequest pkcs10CertificationRequest = new PKCS10CertificationRequest(Base64.getMimeDecoder().decode(p10str));//获取提供的个人信息System.out.println(pkcs10CertificationRequest.getSubject());//获取公钥SubjectPublicKeyInfo subjectPublicKeyInfo = pkcs10CertificationRequest.getSubjectPublicKeyInfo();System.out.println(Base64.getMimeEncoder().encodeToString(subjectPublicKeyInfo.getEncoded()));} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}
运行结果如下: