我正在尝试提取authoritykeyidentifier(oid:2.5.29.35)使用scala中的bouncycastle形成有效证书。
case class ExtendedX509Certificate(x509Certificate : X509Certificate) {
object OID {
val SUBJECT_KEY_IDENTIFIER : String = "2.5.29.14"
val AUTHORITY_KEY_IDENTIFIER : String = "2.5.29.35"
}
我想好了该怎么做了 SubjectKeyIdentifier
:
def getSubjectKeyIdentifier : SubjectKeyIdentifier = {
val encoding : Array[Byte] = x509Certificate.getExtensionValue(OID.SUBJECT_KEY_IDENTIFIER)
SubjectKeyIdentifier.getInstance(encoding)
}
但是,类似的代码 AuthorityKeyIdentifier
不起作用:
def getAuthorityKeyIdentifier : AuthorityKeyIdentifier = {
val encoding : Array[Byte] = x509Certificate.getExtensionValue(OID.AUTHORITY_KEY_IDENTIFIER)
AuthorityKeyIdentifier.getInstance(encoding)
}
}
与以下各项发生碰撞:
java.lang.IllegalArgumentException: unknown object in getInstance: org.bouncycastle.asn1.DEROctetString
为什么不呢´相同的方法对两个标识符不起作用吗?我如何使它起作用?
我正在测试使用:
MIIJcDCCCFigAwIBAgIRAJw0GpsHpPOHAwAAAADLz1cwDQYJKoZIhvcNAQELBQAwQjELMAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczETMBEGA1UEAxMKR1RTIENBIDFPMTAeFw0yMTAzMTYxOTI4MDdaFw0yMTA2MDgxOTI4MDZaMGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgTExDMRUwEwYDVQQDDAwqLmdvb2dsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAStiyrIqG9oMic5xVjELBgdysk+PFeTkM0NITAegkbaq3UQe8kNBcISg8e1oYZK3IPsiTXkJOzVK/EH8hITU7GYo4IHBjCCBwIwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUF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A9lyUL9F3MCIUVBgIMJRWjuNNExkzv98MLyALzE7xZOMAAAF4PLlsZgAABAMARjBEAiAj9/hBHDtUKPzf/rfAvUtsYNUYgJip1ji6033vWQ/jrQIgcop8+lortNPmu2CCKKxw4BGZW1knDLAMxrGp4PJquZEwDQYJKoZIhvcNAQELBQADggEBAE5+iUBlgC5S1ji+aR1vODHbrTzwxZdPc0v/R2R7Pw+/HCRcGx5VrAReKXte/P41x19vRywiLY0leiKUIbOLU5BPU1mJbl4aPSWEIJZbGG2e1655MXKM+O3VvNZDPLCyIULB5rRnu/8Fi1b5YHxiBbzcGNCGLUPXWiG8LkFwxJ//VcWVDMxbfbNP9Tloumged41hsBabAZCO/0KzpmcIjY70fo8xSq5//W0KyxEI5FDt7+pqPnkCyiGzCU4nqe1GzThvxi/zM4GRLW/h5cDSwpjM/RifH1KIHb5nmg8QDaNJwUtUK/KyM478MNWfQ32VixeljVRiwA+QOybuk+B877I=
我用以下方法分析这个文件:
def fromPEMString(cert: String, addWrapperLines: Boolean = false): Option[ExtendedX509Certificate] = {
val PEMString = {
if (addWrapperLines) {
val startLine = "-----BEGIN CERTIFICATE-----"
val endLine = "-----END CERTIFICATE-----"
s"$startLine\n$cert\n$endLine"
} else {
cert
}
}
Option(X509CertUtils.parse(PEMString)) match {
case Some(parsed) => Some(ExtendedX509Certificate(cert, parsed))
case None => None
}
}
1条答案
按热度按时间wqsoz72f1#
好吧,我想我找到错误了。
在里面
您应该传递一个按asn.1八进制字符串排列的字节数组。所以,一种方法是:
我希望我能帮助你。