当前位置: 首页>>代码示例>>Java>>正文


Java PemObject.getContent方法代码示例

本文整理汇总了Java中org.bouncycastle.util.io.pem.PemObject.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java PemObject.getContent方法的具体用法?Java PemObject.getContent怎么用?Java PemObject.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.util.io.pem.PemObject的用法示例。


在下文中一共展示了PemObject.getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPrivateKeyFromPemFile

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private static PrivateKey createPrivateKeyFromPemFile(final String keyFileName) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException 
{
	// Loads a privte key from the specified key file name
    final PemReader pemReader = new PemReader(new FileReader(keyFileName));
    final PemObject pemObject = pemReader.readPemObject();
    final byte[] pemContent = pemObject.getContent();
    pemReader.close();
    final PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(pemContent);
    final KeyFactory keyFactory = getKeyFactoryInstance();
    final PrivateKey privateKey = keyFactory.generatePrivate(encodedKeySpec);
    return privateKey;
}
 
开发者ID:PacktPublishing,项目名称:MQTT-Essentials-A-Lightweight-IoT-Protocol,代码行数:13,代码来源:SecurityHelper.java

示例2: parseObject

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public Object parseObject(PemObject obj)
    throws IOException
{
    try
    {
        PrivateKeyInfo info = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(obj.getContent()));
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(obj.getContent());

        KeyFactory keyFact = KeyFactory.getInstance(info.getPrivateKeyAlgorithm().getAlgorithm().getId(), provider);

        return keyFact.generatePrivate(keySpec);
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing PRIVATE KEY: " + e.toString(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:PEMReader.java

示例3: convert

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static ByteArrayOutputStream convert(final ByteArrayOutputStream baos) {
	try (ByteArrayOutputStream autoCloseableBaos = baos;
			ByteArrayInputStream bais = new ByteArrayInputStream(autoCloseableBaos.toByteArray());
			Reader reader = new InputStreamReader(bais);
			PemReader pemReader = new PemReader(reader)) {
		PemObject pemObject = pemReader.readPemObject();
		if (pemObject == null) {
			throw new DSSException("Unable to read PEM Object");
		}
		byte[] binaries = pemObject.getContent();
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		os.write(binaries, 0, binaries.length);
		return os;
	} catch (IOException e) {
		throw new DSSException("Unable to convert the CRL to DER", e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:18,代码来源:PemToDerConverter.java

示例4: parseChain

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static List<Certificate> parseChain(final String chain) throws IOException, CertificateException {
    Preconditions.checkNotNull(chain);

    final List<Certificate> certs = new ArrayList<Certificate>();
    try(final PemReader pemReader = new PemReader(new StringReader(chain));)
    {
        final PemObject pemObject = pemReader.readPemObject();
        final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
        final ByteArrayInputStream bais = new ByteArrayInputStream(pemObject.getContent());

        for (final Certificate cert : certificateFactory.generateCertificates(bais)) {
            if (cert instanceof X509Certificate) {
                certs.add(cert);
            }
        }
        if (certs.isEmpty()) {
            throw new IllegalStateException("Unable to decode certificate chain");
        }
    }
    return certs;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:22,代码来源:CertificateHelper.java

示例5: parseObject

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
 * Reads in a X509Certificate.
 *
 * @return the X509Certificate
 * @throws IOException if an I/O error occured
 */
public Object parseObject(PemObject obj)
    throws IOException
{
    ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());

    try
    {
        CertificateFactory certFact
            = CertificateFactory.getInstance("X.509", provider);

        return certFact.generateCertificate(bIn);
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing cert: " + e.toString(), e);
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:24,代码来源:PEMReader.java

示例6: parseObject

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
 * Reads in a X509CRL.
 *
 * @return the X509Certificate
 * @throws IOException if an I/O error occured
 */
public Object parseObject(PemObject obj)
    throws IOException
{
    ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());

    try
    {
        CertificateFactory certFact
            = CertificateFactory.getInstance("X.509", provider);

        return certFact.generateCRL(bIn);
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing cert: " + e.toString(), e);
    }
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:24,代码来源:PEMReader.java

示例7: getSocketFactoryFromPEM

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private SSLSocketFactory getSocketFactoryFromPEM(String filePath) throws Exception {
    Security.addProvider(new BouncyCastleProvider());

    PEMParser pemParser = new PEMParser(new FileReader(getConfigFilename(filePath)));
    pemParser.readObject();
    PemObject pemObject = pemParser.readPemObject();
    pemParser.close();

    X509CertificateHolder holder = new X509CertificateHolder(pemObject.getContent());
    X509Certificate bc = new JcaX509CertificateConverter().setProvider("BC")
            .getCertificate(holder);

    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.load(null, null);
    keyStore.setCertificateEntry("ca", bc);

    TrustManager trustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
    SSLContext sslContext = SSLContextUtils.createSSLContext("TLS", null, trustManager);

    return sslContext.getSocketFactory();
}
 
开发者ID:Appdynamics,项目名称:mongo-monitoring-extension,代码行数:22,代码来源:MongoDBMonitor.java

示例8: parseObject

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
 * Reads in a X509Certificate.
 *
 * @return the X509Certificate
 * @throws java.io.IOException if an I/O error occured
 */
public Object parseObject(PemObject obj)
    throws IOException
{
    try
    {
        return new X509CertificateHolder(obj.getContent());
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing cert: " + e.toString(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:19,代码来源:PEMParser.java

示例9: parsePEMFile

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private static byte[] parsePEMFile(File pemFile) throws IOException {
    if (!pemFile.isFile() || !pemFile.exists()) {
        throw new FileNotFoundException(String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath()));
    }
    PemReader reader = new PemReader(new FileReader(pemFile));
    PemObject pemObject = reader.readPemObject();
    byte[] content = pemObject.getContent();
    reader.close();
    return content;
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:11,代码来源:PemUtils.java

示例10: readRsaPrivateKey

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static RSAPrivateKey readRsaPrivateKey(Reader reader) {
    Security.addProvider(new BouncyCastleProvider());
    try {
        KeyFactory factory = KeyFactory.getInstance("RSA", "BC");

        PemReader pemReader = new PemReader(reader);
        PemObject privatePem = pemReader.readPemObject();
        PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privatePem.getContent());
        RSAPrivateKey privateKey = (RSAPrivateKey) factory.generatePrivate(privateSpec);
        return privateKey;
    } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException e) {
        throw new RuntimeException("Unable to extract private RAS Key .", e);
    }
}
 
开发者ID:kodokojo,项目名称:kodokojo,代码行数:15,代码来源:RSAUtils.java

示例11: certificateToDER

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public byte[] certificateToDER(String certificatePEM) {

        byte[] content = null;

        try (PemReader pemReader = new PemReader(new StringReader(certificatePEM))) {
            final PemObject pemObject = pemReader.readPemObject();
            content = pemObject.getContent();

        } catch (IOException e) {
            // best attempt
        }

        return content;
    }
 
开发者ID:hyperledger,项目名称:fabric-sdk-java,代码行数:15,代码来源:CryptoPrimitives.java

示例12: getPemPrivateKey

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static PrivateKey getPemPrivateKey(String filename, String algorithm) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(filename));
    Security.addProvider(new BouncyCastleProvider());
    PemReader pp = new PemReader(br);
    PemObject pem = pp.readPemObject();
    byte[] content = pem.getContent();
    pp.close();

    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(content);
    KeyFactory kf = KeyFactory.getInstance(algorithm);
    return kf.generatePrivate(spec);
}
 
开发者ID:aykutalparslan,项目名称:Telegram-Server,代码行数:13,代码来源:Utilities.java

示例13: getPemPublicKey

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static PublicKey getPemPublicKey(String filename, String algorithm) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(filename));
    Security.addProvider(new BouncyCastleProvider());
    PemReader pp = new PemReader(br);
    PemObject pem = pp.readPemObject();
    byte[] content = pem.getContent();
    pp.close();

    X509EncodedKeySpec spec =
            new X509EncodedKeySpec(content);
    KeyFactory kf = KeyFactory.getInstance(algorithm);
    return kf.generatePublic(spec);
}
 
开发者ID:aykutalparslan,项目名称:Telegram-Server,代码行数:14,代码来源:Utilities.java

示例14: certFromString

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private X509Certificate certFromString(String pem) throws Exception {
    PemObject pemObject = (PemObject) readPemObject(pem);
    ByteArrayInputStream inputStream= new ByteArrayInputStream(pemObject.getContent());
    try {
        CertificateFactory certFact = CertificateFactory.getInstance("X.509");
        return (X509Certificate) certFact.generateCertificate(inputStream);
    } catch (CertificateException e) {
        throw new Exception("problem parsing cert: " + e.toString(),e);
    }
}
 
开发者ID:dasein-cloud,项目名称:dasein-cloud-azurepack,代码行数:11,代码来源:AzureX509.java

示例15: convertToDER

import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
 * This method converts a PEM encoded certificate/crl/... to DER encoded
 * 
 * @param pemContent
 *            the String which contains the PEM encoded object
 * @return the binaries of the DER encoded object
 */
public static byte[] convertToDER(String pemContent) {
	try (Reader reader = new StringReader(pemContent); PemReader pemReader = new PemReader(reader)) {
		PemObject readPemObject = pemReader.readPemObject();
		return readPemObject.getContent();
	} catch (IOException e) {
		throw new DSSException("Unable to convert PEM to DER", e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:16,代码来源:DSSUtils.java


注:本文中的org.bouncycastle.util.io.pem.PemObject.getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。