public class X509CertImpl extends X509Certificate
| Modifier and Type | Class and Description |
|---|---|
static class |
X509CertImpl.EncodedFormat |
| Constructor and Description |
|---|
X509CertImpl(byte[] data) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkValidity()
Checks that the certificate is currently valid, i.e.
|
Set<String> |
getCriticalExtensionOIDs()
Gets a Set of the OID strings for the extension(s) marked
CRITICAL in the certificate/CRL managed by the object
implementing this interface.
|
byte[] |
getEncoded()
Returns the encoded form of this certificate.
|
X509CertImpl.EncodedFormat |
getEncodingFormat() |
byte[] |
getExtensionValue(String oid)
Gets the DER-encoded OCTET string for the extension value
(extnValue) identified by the passed-in
oid
String. |
static X500Principal |
getIssuerX500Principal(X509Certificate cert)
Extract the issuer X500Principal from an X509Certificate.
|
Set<String> |
getNonCriticalExtensionOIDs()
Gets a Set of the OID strings for the extension(s) marked
NON-CRITICAL in the certificate/CRL managed by the object
implementing this interface.
|
PublicKey |
getPublicKey()
Gets the public key from this certificate.
|
static X500Principal |
getSubjectX500Principal(X509Certificate cert)
Extract the subject X500Principal from an X509Certificate.
|
boolean |
hasUnsupportedCriticalExtension()
Check if there is a critical extension that is not supported.
|
String |
toString()
Returns a string representation of this certificate.
|
void |
verify(PublicKey key)
Verifies that this certificate was signed using the
private key that corresponds to the specified public key.
|
void |
verify(PublicKey key,
String sigProvider)
Verifies that this certificate was signed using the
private key that corresponds to the specified public key.
|
getIssuerX500Principal, getSubjectX500Principalequals, getType, hashCodepublic X509CertImpl(byte[] data)
throws CertificateException
CertificateExceptionpublic void checkValidity()
throws CertificateExpiredException,
CertificateNotYetValidException
checkValidity in class X509CertificateCertificateExpiredException - if the certificate has expired.CertificateNotYetValidException - if the certificate is not yet valid.public Set<String> getCriticalExtensionOIDs()
X509Extension
X509Certificate cert = null;
try (InputStream inStrm = new FileInputStream("DER-encoded-Cert")) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
cert = (X509Certificate)cf.generateCertificate(inStrm);
}
Set<String> critSet = cert.getCriticalExtensionOIDs();
if (critSet != null && !critSet.isEmpty()) {
System.out.println("Set of critical extensions:");
for (String oid : critSet) {
System.out.println(oid);
}
}
public byte[] getEncoded()
CertificategetEncoded in class Certificatepublic X509CertImpl.EncodedFormat getEncodingFormat()
public byte[] getExtensionValue(String oid)
X509Extensionoid
String.
The oid string is
represented by a set of nonnegative whole numbers separated
by periods.
For example:
| OID (Object Identifier) | Extension Name |
|---|---|
| 2.5.29.14 | SubjectKeyIdentifier |
| 2.5.29.15 | KeyUsage |
| 2.5.29.16 | PrivateKeyUsage |
| 2.5.29.17 | SubjectAlternativeName |
| 2.5.29.18 | IssuerAlternativeName |
| 2.5.29.19 | BasicConstraints |
| 2.5.29.30 | NameConstraints |
| 2.5.29.33 | PolicyMappings |
| 2.5.29.35 | AuthorityKeyIdentifier |
| 2.5.29.36 | PolicyConstraints |
oid - the Object Identifier value for the extension.public static X500Principal getIssuerX500Principal(X509Certificate cert)
public Set<String> getNonCriticalExtensionOIDs()
X509Extension
CertificateFactory cf = null;
X509CRL crl = null;
try (InputStream inStrm = new FileInputStream("DER-encoded-CRL")) {
cf = CertificateFactory.getInstance("X.509");
crl = (X509CRL)cf.generateCRL(inStrm);
}
byte[] certData = <DER-encoded certificate data>
ByteArrayInputStream bais = new ByteArrayInputStream(certData);
X509Certificate cert = (X509Certificate)cf.generateCertificate(bais);
X509CRLEntry badCert =
crl.getRevokedCertificate(cert.getSerialNumber());
if (badCert != null) {
Set<String> nonCritSet = badCert.getNonCriticalExtensionOIDs();
if (nonCritSet != null)
for (String oid : nonCritSet) {
System.out.println(oid);
}
}
public PublicKey getPublicKey()
getPublicKey in class Certificatepublic static X500Principal getSubjectX500Principal(X509Certificate cert)
public boolean hasUnsupportedCriticalExtension()
X509Extensiontrue if a critical extension is found that is
not supported, otherwise false.public String toString()
CertificatetoString in class Certificatepublic void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
Certificateverify in class Certificatekey - the PublicKey used to carry out the verification.CertificateException - on encoding errors.NoSuchAlgorithmException - on unsupported signature
algorithms.InvalidKeyException - on incorrect key.NoSuchProviderException - if there's no default provider.SignatureException - on signature errors.public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
Certificateverify in class Certificatekey - the PublicKey used to carry out the verification.sigProvider - the name of the signature provider.CertificateException - on encoding errors.NoSuchAlgorithmException - on unsupported signature
algorithms.InvalidKeyException - on incorrect key.NoSuchProviderException - on incorrect provider.SignatureException - on signature errors.