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


Java PEMReader类代码示例

本文整理汇总了Java中org.bouncycastle.openssl.PEMReader的典型用法代码示例。如果您正苦于以下问题:Java PEMReader类的具体用法?Java PEMReader怎么用?Java PEMReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseChain

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
public List<Certificate> parseChain(final String chain) throws IOException {

        final List<Certificate> certs = new ArrayList<>();
        final PEMReader reader = new PEMReader(new StringReader(chain));

        Certificate crt = null;

        while ((crt = (Certificate) reader.readObject()) != null) {
            if (crt instanceof X509Certificate) {
                certs.add(crt);
            }
        }
        if (certs.size() == 0) {
            throw new IllegalArgumentException("Unable to decode certificate chain");
        }

        return certs;
    }
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:CertServiceImpl.java

示例2: parseChain

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
public static List<Certificate> parseChain(final String chain) throws IOException {

        final List<Certificate> certs = new ArrayList<>();
        final PEMReader reader = new PEMReader(new StringReader(chain));

        Certificate crt = null;

        while ((crt = (Certificate) reader.readObject()) != null) {
            if (crt instanceof X509Certificate) {
                certs.add(crt);
            }
        }
        if (certs.size() == 0) {
            throw new IllegalArgumentException("Unable to decode certificate chain");
        }

        return certs;
    }
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:CertificateHelper.java

示例3: doPost

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	Provider provider = null;
	if (null == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)) {
		provider = new BouncyCastleProvider();
		Security.addProvider(provider);
	}
	String serverCertificatePem = request.getParameter("serverCertificate");
	PEMReader pemReader = new PEMReader(new StringReader(serverCertificatePem));
	Object object = pemReader.readObject();
	pemReader.close();
	if (object instanceof X509Certificate) {
		X509Certificate serverCertificate = (X509Certificate) object;
		HttpSession httpSession = request.getSession();
		httpSession.setAttribute("test.be.fedict.eid.applet.model.ChannelBindingServiceBean.serverCertificate",
				serverCertificate);
	}
	response.sendRedirect("channel-binding.jsp");
	if (null != provider) {
		Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:24,代码来源:ChannelBindingConfigServlet.java

示例4: toPrivateKey

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
protected PrivateKey toPrivateKey(String privateKey) {
    StringReader reader = new StringReader(privateKey);

    // プライベートキーを読み込み
    PEMReader pemReader = new PEMReader(reader);
    try {
        Object pemObject = pemReader.readObject();
        KeyPair keyPair = KeyPair.class.cast(pemObject);
        return keyPair.getPrivate();
    } catch (Exception e) {
        // プライベートキーの読み込みに失敗した場合
        throw new AutoApplicationException("ESERVICE-000705", e);
    } finally {
        try {
            pemReader.close();
        } catch (IOException ignore) {
        }
    }
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:20,代码来源:AwsDescribeServiceImpl.java

示例5: PEMKeyManager

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
public PEMKeyManager() {
    try {
        final Properties p = Play.configuration;

        PEMReader keyReader = new PEMReader(new FileReader(Play.getFile(p.getProperty("certificate.key.file",
                                                                                       "conf/host.key"))),
                                            new PasswordFinder() {
            public char[] getPassword() {
                return p.getProperty("certificate.password", "secret").toCharArray();
            }
        });
        key = ((KeyPair) keyReader.readObject()).getPrivate();

        PEMReader reader = new PEMReader(new FileReader(Play.getFile(p.getProperty("certificate.file", "conf/host.cert"))));
        cert = (X509Certificate) reader.readObject();
    } catch (Exception e) {
        e.printStackTrace();
        Logger.error(e, "");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:SslHttpServerContextFactory.java

示例6: read

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
/**
 * Reads a certificate from an input stream for a given provider
 * @param input the input stream
 * @param provider the certificate provider
 * @return the certificate
 * @throws CertificateException
 * @throws IOException
 */
public X509Certificate read(InputStream input, Provider provider)
  throws CertificateException, IOException
{
  X509Certificate		certificate;

  certificate = (X509Certificate) CertificateFactory.getInstance("X.509", provider).generateCertificate(input);
  
  if (certificate == null) {
    PEMReader reader = new PEMReader(new InputStreamReader(input));
    certificate = (X509Certificate)(reader).readObject();
    reader.close();
  }

  return certificate;
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:24,代码来源:KeyStoreManager.java

示例7: loadCertificateFromFile

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
/**
 * Loads an X.509 certificate from file
 * @param filename File to load from
 * @return Valid X509Certificate or null
 * @throws IOException
 */
public static X509Certificate loadCertificateFromFile(String filename) throws IOException {

    X509Certificate cert = null;

    try {
        final Reader reader = new FileReader(filename);
        final PEMReader pemReader = new PEMReader(reader);

        Object object;
        while ((object = pemReader.readObject()) != null){
            if (object instanceof X509Certificate) {
                cert = (X509Certificate) object;
            }
        }

        reader.close();
        return cert;
    } catch (FileNotFoundException e){
        return null;
    }

}
 
开发者ID:PaulMaddox,项目名称:ssl-ca,代码行数:29,代码来源:CertificateAuthority.java

示例8: loadKeyPairFromFile

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
/**
 * Loads a KeyPair from file
 * @param filename File to load from
 * @return Valid KeyPair or null
 * @throws IOException
 */
public static KeyPair loadKeyPairFromFile(String filename) throws IOException {

    KeyPair keyPair = null;

    try {

        final Reader reader = new FileReader(filename);
        final PEMReader pemReader = new PEMReader(reader);

        Object object;
        while((object = pemReader.readObject()) != null){
            if(object instanceof KeyPair) {
                keyPair = (KeyPair) object;
            }
        }

        reader.close();
        return keyPair;

    } catch (FileNotFoundException e){
        return null;
    }

}
 
开发者ID:PaulMaddox,项目名称:ssl-ca,代码行数:31,代码来源:CertificateAuthority.java

示例9: encryptedTest

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
private void encryptedTest(PrivateKey key, ASN1ObjectIdentifier algorithm)
    throws NoSuchProviderException, NoSuchAlgorithmException, IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut), "BC");
    PKCS8Generator pkcs8 = new PKCS8Generator(key, algorithm, "BC");

    pkcs8.setPassword("hello".toCharArray());
    
    pWrt.writeObject(pkcs8);

    pWrt.close();

    PEMReader pRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())), new PasswordFinder()
    {
        public char[] getPassword()
        {
            return "hello".toCharArray();
        }
    });

    PrivateKey rdKey = (PrivateKey)pRd.readObject();

    assertEquals(key, rdKey);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:AllTests.java

示例10: doOpenSslTestFile

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
private void doOpenSslTestFile(
    String  fileName,
    Class   expectedPrivKeyClass)
    throws IOException
{
    PEMReader pr = openPEMResource("data/" + fileName, new Password("changeit".toCharArray()));
    Object o = pr.readObject();

    if (o == null || !(o instanceof KeyPair))
    {
        fail("Didn't find OpenSSL key");
    }

    KeyPair kp = (KeyPair) o;
    PrivateKey privKey = kp.getPrivate();

    if (!expectedPrivKeyClass.isInstance(privKey))
    {
        fail("Returned key not of correct type");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:ReaderTest.java

示例11: doNoPasswordTest

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
private void doNoPasswordTest()
    throws IOException
{
    PasswordFinder pGet = new Password("".toCharArray());

    PEMReader pemRd = openPEMResource("smimenopw.pem", pGet);
    Object o;
    PrivateKey key = null;

    while ((o = pemRd.readObject()) != null)
    {
         key = (PrivateKey)o;
    }

    if (key == null)
    {
        fail("private key not detected");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:20,代码来源:ReaderTest.java

示例12: extractPublicRSAKey

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
/**
 * makes RSA public key from PEM string
 * 
 * @param s    PEM string that contains the key
 * @return
 * @see JCERSAPublicKey
 */
public static RSAPublicKey extractPublicRSAKey(String s) {
    RSAPublicKey theKey;
    try {
        PEMReader reader = new PEMReader(new StringReader(s));
        Object o = reader.readObject();
        if (!(o instanceof JCERSAPublicKey)) {
            throw new IOException("Encryption.extractPublicRSAKey: no public key found in string '" + s + "'");
        }
        JCERSAPublicKey JCEKey = (JCERSAPublicKey) o;
        theKey = getRSAPublicKey(JCEKey.getModulus(), JCEKey.getPublicExponent());
   
    } catch (Exception e) {
        log.warning("Encryption.extractPublicRSAKey: Caught exception:" + e.getMessage());
        theKey = null;
    }

    return theKey;
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:26,代码来源:Encryption.java

示例13: makeKeyPair

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
public static KeyPair makeKeyPair(String publicKeyString,
		String privateKeyString) throws SshProxyJException {
	PublicKey publicKey = null;
	KeyPair kp = null;
	try {
		PublicKeyRead pkr = new PublicKeyRead();
		publicKey = pkr.decodePublicKey(publicKeyString);

		StringReader r = new StringReader(privateKeyString);
		PEMReader pr = new PEMReader(r);
			kp = (KeyPair) pr.readObject();
		pr.close();
	} catch (IOException e) {
		throw new SshProxyJException("Failed to decode private key", e);
	}
	return new KeyPair(publicKey, kp.getPrivate());
}
 
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:18,代码来源:KeyUtils.java

示例14: openPEMResource

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
private PEMReader openPEMResource(
        String          fileName,
        PasswordFinder  pGet) throws FileNotFoundException
{
 InputStream res = new BufferedInputStream(new FileInputStream(fileName));
    Reader fRd = new BufferedReader(new InputStreamReader(res));
    return new PEMReader(fRd, pGet);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:9,代码来源:CmsCryptoOpenSSLImpl.java

示例15: parseCertificate

import org.bouncycastle.openssl.PEMReader; //导入依赖的package包/类
public Certificate parseCertificate(final String cert) {
    final PEMReader certPem = new PEMReader(new StringReader(cert));
    try {
        return (Certificate) certPem.readObject();
    } catch (final Exception e) {
        throw new InvalidParameterValueException("Invalid Certificate format. Expected X509 certificate. Failed due to " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(certPem);
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:11,代码来源:CertServiceImpl.java


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