public final class UtilsCertificateTsl
extends java.lang.Object
Class that provides methods for managing certificates.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
19/09/2022.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
X509_TYPE
Constant that represents a "X.509" Certificate type.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
canonicalizarIdCertificado(java.lang.String idCertificado)
Method that canonicalizes the identifier of a certificate.
|
static boolean |
equals(java.security.cert.X509Certificate cert1,
java.security.cert.X509Certificate cert2)
Method that indicates whether some other certificate is "equal to" this one (
true) or not (false). |
static org.bouncycastle.asn1.x509.Certificate |
getBouncyCastleCertificate(byte[] certificate)
Creates a BouncyCastle X509Certificate given its content.
|
static org.bouncycastle.asn1.x509.Certificate |
getBouncyCastleCertificate(java.security.cert.Certificate x509cert)
Creates a BouncyCastle X509Certificate from a java X509Certificate.
|
static java.lang.String |
getCertificateId(java.security.cert.X509Certificate cert)
Gets certificate´s identifier (canonicalized subject).
|
static java.lang.String |
getCertificateIssuerId(java.security.cert.X509Certificate cert)
Method that obtains the canonicalized identifier of the issuer of a certificate.
|
static java.lang.String |
getCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
Gets the country specified in the subject name of the input certificate if it is a CA certificate, or from
the issuer if it is a end certificate.
|
static java.lang.String |
getIssuerCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
Gets the country specified in the issuer name of the input certificate.
|
static java.lang.String |
getRDNFirstValueFromX500Name(org.bouncycastle.asn1.x500.X500Name x500Name,
org.bouncycastle.asn1.ASN1ObjectIdentifier rdnAsn1ObjectIdentifier)
Gets the RDN First ocurrence value with the OID indicated from the input X500Name.
|
static java.lang.String |
getRDNFirstValueFromX500Principal(javax.security.auth.x500.X500Principal x500Principal,
org.bouncycastle.asn1.ASN1ObjectIdentifier rdnAsn1ObjectIdentifier)
Gets the RDN First ocurrence value with the OID indicated from the input X.500 Principal.
|
static java.lang.String |
getSubjectCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
Gets the country specified in the subject name of the input certificate.
|
static java.security.cert.X509Certificate |
getX509Certificate(byte[] certificate)
Creates a X509Certificate given its content.
|
static boolean |
hasCertKeyPurposeTimeStamping(java.security.cert.X509Certificate cert)
Checks if the input certificate has the key purpose for TimeStamping.
|
static boolean |
isCA(java.security.cert.X509Certificate cert)
Checks if the input certificate is a CA (it has the flag in the basic constraint).
|
static boolean |
isSelfSigned(java.security.cert.X509Certificate cert)
Method that checks whether a certificate is self-signed (
true) or not (false). |
static boolean |
verify(java.security.PublicKey publicKey,
java.security.cert.X509Certificate cert)
Checks if a given public key corresponds to the private key that signed the input certificate.
|
static boolean |
verify(java.security.cert.X509Certificate certIssuer,
java.security.cert.X509Certificate cert)
Checks if a given certificate is issued by another one.
|
public static final java.lang.String X509_TYPE
public static java.security.cert.X509Certificate getX509Certificate(byte[] certificate)
throws CommonUtilsException
certificate - Certificate content.CommonUtilsException - Exception thrown if there is any problem creating the certificate.public static java.lang.String getRDNFirstValueFromX500Principal(javax.security.auth.x500.X500Principal x500Principal,
org.bouncycastle.asn1.ASN1ObjectIdentifier rdnAsn1ObjectIdentifier)
x500Principal - X.500 Principal to analyze.rdnAsn1ObjectIdentifier - Object Identifier that represents the RDN to search.null if some of the input parameters are null or there is some
error analyzing the X.500 Principal.public static java.lang.String getRDNFirstValueFromX500Name(org.bouncycastle.asn1.x500.X500Name x500Name,
org.bouncycastle.asn1.ASN1ObjectIdentifier rdnAsn1ObjectIdentifier)
x500Name - X.500 Name to analyze.rdnAsn1ObjectIdentifier - Object Identifier that represents the RDN to search.null if some of the input parameters are null or there is some
error analyzing the X.500 Name.public static boolean equals(java.security.cert.X509Certificate cert1,
java.security.cert.X509Certificate cert2)
throws CommonUtilsException
true) or not (false).cert1 - Parameter that represents the first certificate to compare.cert2 - Parameter that represents the second certificate to compare.true) or not (false).CommonUtilsException - If there is some error getting de issuer information from the input certificates.public static java.lang.String getCertificateIssuerId(java.security.cert.X509Certificate cert)
throws CommonUtilsException
cert - Parameter that represents the certificate.CommonUtilsException - If the method fails.public static java.lang.String canonicalizarIdCertificado(java.lang.String idCertificado)
idCertificado - Parameter that represents the identifier of a certificate.public static boolean verify(java.security.PublicKey publicKey,
java.security.cert.X509Certificate cert)
throws CommonUtilsException
publicKey - Public key to use to verify the certificate.cert - Certificate to check.true if the public key verifies the certificate.CommonUtilsException - if there is any problem verifying the certificate.public static boolean verify(java.security.cert.X509Certificate certIssuer,
java.security.cert.X509Certificate cert)
throws CommonUtilsException
certIssuer - Issuer to checkcert - Certificate to be checked.true if the input certificate is issued by the specified issuer certificate,
otherwise false.CommonUtilsException - Exception thrown if there is any problem verifying the certificates.public static java.lang.String getCertificateId(java.security.cert.X509Certificate cert)
throws CommonUtilsException
cert - Certificate to get the identifier.CommonUtilsException - Exception thrown if there is any problem creating the certificate.public static boolean isSelfSigned(java.security.cert.X509Certificate cert)
true) or not (false).cert - Parameter that represents the certificate.true) or not (false).public static boolean hasCertKeyPurposeTimeStamping(java.security.cert.X509Certificate cert)
throws CommonUtilsException
cert - X509v3 certificate to check.true if the input certificate has the key purpose for timestamping, otherwise false.CommonUtilsException - In case of some error extracting the keyPurpose extension from the certificate.public static boolean isCA(java.security.cert.X509Certificate cert)
cert - X509v3 certificate that must be checked.true if the input certificate has the BasicConstraint extension
with the CA flag, otherwise false (including if the input is null).public static java.lang.String getCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
x509cert - X509 Certificate to analyze to obtain the country.null in case of some error or the country is not defined.public static java.lang.String getSubjectCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
x509cert - X509 Certificate to analyze to obtain the country of its subject name.null in case of some error or the country is not defined.public static java.lang.String getIssuerCountryOfTheCertificateString(java.security.cert.X509Certificate x509cert)
x509cert - X509 Certificate to analyze to obtain the country of its issuer name.null in case of some error or the country is not defined.public static org.bouncycastle.asn1.x509.Certificate getBouncyCastleCertificate(java.security.cert.Certificate x509cert)
throws CommonUtilsException
x509cert - Certificate to transform.CommonUtilsException - Exception thrown if there is any problem creating the certificate.public static org.bouncycastle.asn1.x509.Certificate getBouncyCastleCertificate(byte[] certificate)
throws CommonUtilsException
certificate - Certificate content.CommonUtilsException - Exception thrown if there is any problem creating the certificate.