gpt4 book ai didi

android - android中的证书解析器

转载 作者:行者123 更新时间:2023-11-29 14:01:08 25 4
gpt4 key购买 nike

我想知道我是否在这个例子中遗漏了一些代码。我在这个类中的 certHeader、certFooter 上遇到编译时错误。如果有人可以给我一个简短的想法,那将是有帮助的。或者如果一些一个关于证书解析器的更好示例会有所帮助。我正在使用此示例来解析证书。

try 
{
String abc = "-----BEGIN CERTIFICATE-----\n" + "ALneIwerZ5Nu+z1Yjvdco9sOHfkhYW4nL+FIlGDGIS +YsyevB8YN2hBnog7gtQ6PB+sVF6o/1UdU\n" + // lines deleted for brevity "rchFUEChHZ5G7AAk02K7/iyqITc/IPNHHpilTg/NB6QhF9s=\n" + "-----END CERTIFICATE-----";

int headerIndex = abc.indexOf(certHeader);
if (headerIndex == -1)
{
throw new CertificateParsingException("cannot find BEGIN CERTIFICATE");
}
int startIndex = headerIndex + certHeader.length();

int endIndex = abc.indexOf(certFooter);
if (endIndex == -1)
{
throw new CertificateParsingException("cannot find END CERTIFICATE"); }

String cert = abc.substring(startIndex, endIndex);
byte[] certBytes = cert.getBytes();

InputStream in = new Base64InputStream(new ByteArrayInputStream(certBytes));

CertificateFactory certFact = CertificateFactory.getInstance ("X.509");
Certificate certGen = certFact.generateCertificate(in);
X509Certificate x509 = (X509Certificate)
certGen;
}
catch (Exception e)
{
Log.e("testapp", "exception: " + e.getMessage());
}

最佳答案

certHeadercertFooter 应该是 int 变量。从您向我们展示的内容来看,您似乎没有在任何地方声明它们。

来自String.indexOf文档:

Returns the index within this string of the first occurrence of the specified character. If a character with value ch occurs in the character sequence represented by this String object, then the index (in Unicode code units) of the first such occurrence is returned. For values of ch in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that:

this.charAt(k) == ch

关于android - android中的证书解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9469899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com