edu.vt.middleware.crypt.io.X509CertificateCredentialReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vt-crypt Show documentation
Show all versions of vt-crypt Show documentation
Library for performing common cryptographic operations
/*
$Id: X509CertificateCredentialReader.java 1818 2011-02-08 19:19:09Z dfisher $
Copyright (C) 2007-2011 Virginia Tech.
All rights reserved.
SEE LICENSE FOR MORE INFORMATION
Author: Middleware Services
Email: [email protected]
Version: $Revision: 1818 $
Updated: $Date: 2011-02-08 14:19:09 -0500 (Tue, 08 Feb 2011) $
*/
package edu.vt.middleware.crypt.io;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import edu.vt.middleware.crypt.CryptException;
import edu.vt.middleware.crypt.CryptProvider;
/**
* Reads X.509 certificates from encoded representation. Both PEM and DER
* encodings are supported.
*
* @author Middleware Services
* @version $Revision: 1818 $
*/
public class X509CertificateCredentialReader
implements CredentialReader
{
/** Certificate type. */
private static final String CERTIFICATE_TYPE = "X.509";
/** {@inheritDoc} */
public X509Certificate read(final File file)
throws IOException, CryptException
{
return read(new BufferedInputStream(new FileInputStream(file)));
}
/** {@inheritDoc} */
public X509Certificate read(final InputStream in)
throws IOException, CryptException
{
try {
final CertificateFactory cf = CryptProvider.getCertificateFactory(
CERTIFICATE_TYPE);
return (X509Certificate) cf.generateCertificate(in);
} catch (CertificateException e) {
throw new CryptException("Failed reading X.509 certificate.", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy