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


Java PEMReader.readObject方法代码示例

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


在下文中一共展示了PEMReader.readObject方法的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: 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:mlundblad,项目名称:bc-java,代码行数:22,代码来源:ReaderTest.java

示例7: 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

示例8: 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

示例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:mlundblad,项目名称:bc-java,代码行数:26,代码来源:AllTests.java

示例10: 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

示例11: parsePrivateKey

import org.bouncycastle.openssl.PEMReader; //导入方法依赖的package包/类
public PrivateKey parsePrivateKey(final String key, final String password) throws IOException {

        PasswordFinder pGet = null;

        if (password != null) {
            pGet = new KeyPassword(password.toCharArray());
        }

        final PEMReader privateKey = new PEMReader(new StringReader(key), pGet);
        Object obj = null;
        try {
            obj = privateKey.readObject();
        } finally {
            IOUtils.closeQuietly(privateKey);
        }

        try {

            if (obj instanceof KeyPair) {
                return ((KeyPair) obj).getPrivate();
            }

            return (PrivateKey) obj;
        } catch (final Exception e) {
            throw new IOException("Invalid Key format or invalid password.", e);
        }
    }
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:28,代码来源:CertServiceImpl.java

示例12: getFingerprint

import org.bouncycastle.openssl.PEMReader; //导入方法依赖的package包/类
/**
 * Obtains the fingerprint of the key in the "ab:cd:ef:...:12" format.
 */
public String getFingerprint() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    Reader r = new BufferedReader(new StringReader(privateKey.toString()));
    PEMReader pem = new PEMReader(r,new PasswordFinder() {
        public char[] getPassword() {
            throw PRIVATE_KEY_WITH_PASSWORD;
        }
    });

    try {
        KeyPair pair = (KeyPair) pem.readObject();
        if(pair==null)  return null;
        PrivateKey key = pair.getPrivate();
        return digest(key);
    } catch (RuntimeException e) {
        if (e==PRIVATE_KEY_WITH_PASSWORD)
            throw new IOException("This private key is password protected, which isn't supported yet");
        throw e;
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:24,代码来源:EC2PrivateKey.java

示例13: getPublicFingerprint

import org.bouncycastle.openssl.PEMReader; //导入方法依赖的package包/类
public String getPublicFingerprint() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    Reader r = new BufferedReader(new StringReader(privateKey.toString()));
    PEMReader pem = new PEMReader(r,new PasswordFinder() {
        public char[] getPassword() {
            throw PRIVATE_KEY_WITH_PASSWORD;
        }
    });

    try {
        KeyPair pair = (KeyPair) pem.readObject();
        if(pair==null)  return null;
        PublicKey key = pair.getPublic();
        return digestOpt(key,"MD5");
    } catch (RuntimeException e) {
        if (e==PRIVATE_KEY_WITH_PASSWORD)
            throw new IOException("This private key is password protected, which isn't supported yet");
        throw e;
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:21,代码来源:EC2PrivateKey.java

示例14: stringToKeyPair

import org.bouncycastle.openssl.PEMReader; //导入方法依赖的package包/类
private KeyPair stringToKeyPair(String keyPairString) throws IOException {
	StringReader stringReader = new StringReader(keyPairString);
	PEMReader pemReader = new PEMReader(stringReader);
	Object obj = pemReader.readObject();
	if (obj instanceof KeyPair) {
		return (KeyPair) obj;
	} else {
		throw new IOException(
				"Reader did not produce a key pair but an object of type "
						+ obj.getClass().getName());
	}
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:13,代码来源:ScmKeyPairProvider.java

示例15: decodeCert

import org.bouncycastle.openssl.PEMReader; //导入方法依赖的package包/类
/**
 * Decodes the given certificate from PEM format.
 *
 * @param pemCert
 *            PEM-encoded certificate text to decode.
 *
 * @return Certificate.
 *
 * @throws IOException
 *             On decoding error.
 */
@SuppressWarnings("resource")
public static Certificate decodeCert(final String pemCert)
		throws IOException {
	final PEMReader reader = new PEMReader(new StringReader(pemCert));
	final Certificate cert = (Certificate) reader.readObject();
	if (cert != null) {
		return cert;
	} else {
		throw new IOException("Error decoding certificate.");
	}
}
 
开发者ID:shivam091,项目名称:Java-Security,代码行数:23,代码来源:PemHelper.java


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