當前位置: 首頁>>代碼示例>>Java>>正文


Java JcaPEMWriter類代碼示例

本文整理匯總了Java中org.bouncycastle.openssl.jcajce.JcaPEMWriter的典型用法代碼示例。如果您正苦於以下問題:Java JcaPEMWriter類的具體用法?Java JcaPEMWriter怎麽用?Java JcaPEMWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JcaPEMWriter類屬於org.bouncycastle.openssl.jcajce包,在下文中一共展示了JcaPEMWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exportCertificate

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
@Override
public boolean exportCertificate(File file, int i) {
    try {
        if (i == 0) {
            OutputStream outputStream = new FileOutputStream(file);
            outputStream.write(currentCertificate.getEncoded());
            outputStream.flush();
            outputStream.close();
        } else {
            FileWriter fileWriter = new FileWriter(file);
            JcaPEMWriter pemWriter = new JcaPEMWriter(fileWriter);
            pemWriter.writeObject(currentCertificate);
        }
    } catch (CertificateEncodingException | IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
開發者ID:stevanmilic,項目名稱:X509-certificate-manager,代碼行數:20,代碼來源:MyCode.java

示例2: convertX509CertToPem

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
public String convertX509CertToPem( X509Certificate x509Cert )
{
    try
    {
        StringWriter sw = new StringWriter();
        try ( JcaPEMWriter pw = new JcaPEMWriter( sw ) )
        {
            pw.writeObject( x509Cert );
        }
        return sw.toString();
    }
    catch ( IOException e )
    {
        throw new ActionFailedException( "Failed to convert certificate to PEM", e );
    }
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:17,代碼來源:CertificateTool.java

示例3: rebuildKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
/**
 * Rebuild the {@link KeyPair} associated with the submitted {@link PrivateKey}.
 *
 * @param privateKey The {@link PrivateKey} to rebuild the {@link KeyPair} for.
 * @return The rebuild {@link KeyPair}.
 * @throws IOException if an I/O error occurs during the rebuild.
 */
public static KeyPair rebuildKeyPair(PrivateKey privateKey) throws IOException {
	StringWriter stringWriter = new StringWriter();

	try (JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter)) {
		pemWriter.writeObject(privateKey);
		pemWriter.flush();
	}

	StringReader stringReader = new StringReader(stringWriter.toString());
	Object pemObject;

	try (PEMParser pemParser = new PEMParser(stringReader)) {
		pemObject = pemParser.readObject();
	}

	if (!(pemObject instanceof PEMKeyPair)) {
		throw new IOException("Unexpected pem object: " + pemObject);
	}

	PEMKeyPair pemKeyPair = (PEMKeyPair) pemObject;

	return PEM_KEY_CONVERTER.getKeyPair(pemKeyPair);
}
 
開發者ID:hdecarne,項目名稱:certmgr,代碼行數:31,代碼來源:KeyHelper.java

示例4: writeCertObject

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private static void writeCertObject(JcaPEMWriter writer, String resource, CertObjectStore.Entry storeEntry)
		throws IOException {
	switch (storeEntry.type()) {
	case CRT:
		writeObject(writer, resource, storeEntry.getCRT());
		break;
	case KEY:
		writeObject(writer, resource, storeEntry.getKey());
		break;
	case CSR:
		writeObject(writer, resource, storeEntry.getCSR().toPKCS10());
		break;
	case CRL:
		writeObject(writer, resource, storeEntry.getCRL());
		break;
	}
}
 
開發者ID:hdecarne,項目名稱:certmgr,代碼行數:18,代碼來源:PEMCertReaderWriter.java

示例5: writeEncryptedCertObject

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private static void writeEncryptedCertObject(JcaPEMWriter writer, String resource, CertObjectStore.Entry storeEntry,
		PasswordCallback newPassword) throws IOException {
	switch (storeEntry.type()) {
	case CRT:
		writeObject(writer, resource, storeEntry.getCRT());
		break;
	case KEY:
		writeEncryptedObject(writer, resource, storeEntry.getKey(), newPassword);
		break;
	case CSR:
		writeObject(writer, resource, storeEntry.getCSR().toPKCS10());
		break;
	case CRL:
		writeObject(writer, resource, storeEntry.getCRL());
		break;
	}
}
 
開發者ID:hdecarne,項目名稱:certmgr,代碼行數:18,代碼來源:PEMCertReaderWriter.java

示例6: pem

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
@Override
public byte[] pem() {
    // create byte array stream and wrap it in a writer
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer destination = new OutputStreamWriter(baos);

    // write (unwrapped object)
    try(final JcaPEMWriter pemWriter = new JcaPEMWriter(destination)) {
        pemWriter.writeObject(this.unwrap());
    } catch (IOException e) {
        // todo: log error

        // return 0 bytes
        return new byte[0];
    }

    final byte[] bytes = baos.toByteArray();

    return bytes;
}
 
開發者ID:chrisruffalo,項目名稱:simple-ssl,代碼行數:21,代碼來源:KeyImpl.java

示例7: getPEMStringFromRSAKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
/**
 * Converts RSA private key to PEM string.
 *
 * @param rsaKeyPair
 * @return PEM string
 */
public static String getPEMStringFromRSAKeyPair(final RSAKeyPair rsaKeyPair) {
    final StringWriter pemStrWriter = new StringWriter();
    final JcaPEMWriter pemWriter = new JcaPEMWriter(pemStrWriter);
    try {
        final KeyPair keyPair = new KeyPair(rsaKeyPair.getPublic(), rsaKeyPair.getPrivate());
        pemWriter.writeObject(keyPair.getPrivate());
        pemWriter.close();

    } catch (final IOException e) {
        logger.warn("Caught exception:" + e.getMessage());
        return "";
    }

    return pemStrWriter.toString();
}
 
開發者ID:rovemonteux,項目名稱:silvertunnel-monteux,代碼行數:22,代碼來源:Encryption.java

示例8: serializePrivateKey

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private byte[] serializePrivateKey(final KeyPair keyPair,
                                   final String passphrase) throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(new OutputStreamWriter(baos,
            StandardCharsets.US_ASCII));

    if (passphrase != null) {
        final PEMEncryptor pemEncryptor = new JcePEMEncryptorBuilder("AES-128-CBC").build(passphrase.toCharArray());
        final JcaMiscPEMGenerator pemGenerator = new JcaMiscPEMGenerator(keyPair.getPrivate(), pemEncryptor);
        jcaPEMWriter.writeObject(pemGenerator);
    } else {
        jcaPEMWriter.writeObject(keyPair.getPrivate());
    }

    jcaPEMWriter.flush();
    jcaPEMWriter.close();
    return baos.toByteArray();
}
 
開發者ID:joyent,項目名稱:java-http-signature,代碼行數:19,代碼來源:KeyPairLoaderTest.java

示例9: convertCertificateToPEM

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private static String convertCertificateToPEM(X509Certificate signedCertificate) throws IOException {
    StringWriter signedCertificatePEMDataStringWriter = new StringWriter();
    JcaPEMWriter pemWriter                            = new JcaPEMWriter(signedCertificatePEMDataStringWriter);
    pemWriter.writeObject(signedCertificate);
    pemWriter.close();
    return signedCertificatePEMDataStringWriter.toString();
}
 
開發者ID:Zubnix,項目名稱:rtcdcjava,代碼行數:8,代碼來源:RTCCertificate.java

示例10: getStringFromPublicKey

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private static String getStringFromPublicKey(PublicKey pubKey) throws InvalidKeyPairException {
    try {
        StringWriter writer = new StringWriter();
        JcaPEMWriter pemWriter = new JcaPEMWriter(writer);
        pemWriter.writeObject(pubKey);
        pemWriter.close();
        return writer.toString();
    } catch (IOException e) {
        throw new InvalidKeyPairException("Could not encode public key. PEM encoding failed.",
                e);
    }
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:13,代碼來源:Crypto.java

示例11: convertObject

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
private String convertObject(Object obj) throws IOException {
	try (StringWriter sw = new StringWriter(); JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) {
		pemWriter.writeObject(obj);
		pemWriter.close();
		return sw.toString();
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:8,代碼來源:XTFKeyStore.java

示例12: exportPem

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
public static void exportPem(File exportFile, Object... certs) throws GeneralSecurityException, IOException {
    try (JcaPEMWriter pw = new JcaPEMWriter(new FileWriter(exportFile))) {
        for (Object cert : certs) {
            pw.writeObject(cert);
            pw.flush();
        }
    }
}
 
開發者ID:ganskef,項目名稱:shortcircuit-proxy,代碼行數:9,代碼來源:MitmCertificate.java

示例13: toPEMFormat

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
public static String toPEMFormat(Key key) {
    StringWriter sw = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(sw);
    try {
        pemWriter.writeObject(key);
        pemWriter.close();

        return sw.toString();

    } catch (IOException x) {
        throw new RuntimeException("Failed to serialize key", x);
    }
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:14,代碼來源:KeyUtil.java

示例14: toPEMformat

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
/**
 * Serialize Certificate in PEM format
 */
public static String toPEMformat(X509Certificate certificate) {
    StringWriter sw = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(sw);
    try {
        pemWriter.writeObject(certificate);
        pemWriter.close();

        return sw.toString();

    } catch (IOException x) {
        throw new RuntimeException("Failed to serialize certificate", x);
    }
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:17,代碼來源:CertificateUtil.java

示例15: certificationRequestToPEM

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //導入依賴的package包/類
/**
 * certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM
 * format.
 *
 * @param csr The Certificate to convert
 * @return An equivalent PEM format certificate.
 * @throws IOException
 */

private String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException {
    PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded());

    StringWriter str = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(str);
    pemWriter.writeObject(pemCSR);
    pemWriter.close();
    str.close();
    return str.toString();
}
 
開發者ID:hyperledger,項目名稱:fabric-sdk-java,代碼行數:20,代碼來源:CryptoPrimitives.java


注:本文中的org.bouncycastle.openssl.jcajce.JcaPEMWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。