All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spongycastle.jce.PrincipalUtil Maven / Gradle / Ivy

Go to download

Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android. Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add an alternative (updated/complete) Bouncy Castle jar. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.

The newest version!
package org.spongycastle.jce;

import java.io.*;
import java.security.cert.*;

import org.spongycastle.asn1.*;
import org.spongycastle.asn1.x509.*;

/**
 * a utility class that will extract X509Principal objects from X.509 certificates.
 * 

* Use this in preference to trying to recreate a principal from a String, not all * DNs are what they should be, so it's best to leave them encoded where they * can be. */ public class PrincipalUtil { /** * return the issuer of the given cert as an X509PrincipalObject. */ public static X509Principal getIssuerX509Principal( X509Certificate cert) throws CertificateEncodingException { try { TBSCertificateStructure tbsCert = TBSCertificateStructure.getInstance( ASN1Object.fromByteArray(cert.getTBSCertificate())); return new X509Principal(tbsCert.getIssuer()); } catch (IOException e) { throw new CertificateEncodingException(e.toString()); } } /** * return the subject of the given cert as an X509PrincipalObject. */ public static X509Principal getSubjectX509Principal( X509Certificate cert) throws CertificateEncodingException { try { TBSCertificateStructure tbsCert = TBSCertificateStructure.getInstance( ASN1Object.fromByteArray(cert.getTBSCertificate())); return new X509Principal(tbsCert.getSubject()); } catch (IOException e) { throw new CertificateEncodingException(e.toString()); } } /** * return the issuer of the given CRL as an X509PrincipalObject. */ public static X509Principal getIssuerX509Principal( X509CRL crl) throws CRLException { try { TBSCertList tbsCertList = TBSCertList.getInstance( ASN1Object.fromByteArray(crl.getTBSCertList())); return new X509Principal(tbsCertList.getIssuer()); } catch (IOException e) { throw new CRLException(e.toString()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy