如何解析安全证书子组件? [英] How to parse security certificate subcomponents?
本文介绍了如何解析安全证书子组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从安全证书中读取主题,该证书的格式如下...
I'm reading the subject from a security certificate, which has the following format...
CN=x,OU=y,O=z,ST=v,C=COM
我想解析此String
并仅获取CN
.有没有简单的方法可以做到这一点?
I want to parse this String
and get the CN
only. Is there any easy way to do this?
推荐答案
是否可以在此处使用简单的正则表达式?
Is it possible to use simple regular expressions here?
没有尝试就没想到:
Pattern pattern = Pattern.compile("CN=([^\\,])\\,")
Matcher matcher = pattern.matcher(text);
if ( matcher.find() )
{
for (int index=1; index<matcher.groupCount();index++)
{
String cnValue = matcher.group(index);
}
}
这篇关于如何解析安全证书子组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文