org.bouncycastle.cms.jcajce.JcaSelectorConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk15to18 Show documentation
Show all versions of bcpkix-jdk15to18 Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.cms.jcajce;
import java.io.IOException;
import java.security.cert.X509CertSelector;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.cms.KeyTransRecipientId;
import org.bouncycastle.cms.SignerId;
public class JcaSelectorConverter
{
public JcaSelectorConverter()
{
}
public SignerId getSignerId(X509CertSelector certSelector)
{
try
{
if (certSelector.getSubjectKeyIdentifier() != null)
{
return new SignerId(X500Name.getInstance(certSelector.getIssuerAsBytes()), certSelector.getSerialNumber(), ASN1OctetString.getInstance(certSelector.getSubjectKeyIdentifier()).getOctets());
}
else
{
return new SignerId(X500Name.getInstance(certSelector.getIssuerAsBytes()), certSelector.getSerialNumber());
}
}
catch (IOException e)
{
throw new IllegalArgumentException("unable to convert issuer: " + e.getMessage());
}
}
public KeyTransRecipientId getKeyTransRecipientId(X509CertSelector certSelector)
{
try
{
if (certSelector.getSubjectKeyIdentifier() != null)
{
return new KeyTransRecipientId(X500Name.getInstance(certSelector.getIssuerAsBytes()), certSelector.getSerialNumber(), ASN1OctetString.getInstance(certSelector.getSubjectKeyIdentifier()).getOctets());
}
else
{
return new KeyTransRecipientId(X500Name.getInstance(certSelector.getIssuerAsBytes()), certSelector.getSerialNumber());
}
}
catch (IOException e)
{
throw new IllegalArgumentException("unable to convert issuer: " + e.getMessage());
}
}
}