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


Java PEMWriter.writeObject方法代码示例

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


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

示例1: saveKeyPairAndCertificateToFile

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
protected void saveKeyPairAndCertificateToFile() throws Exception {
    if(localPrivateKeyFile==null){
      LOGGER.info("not saving private key nor certificate");
      return;
    }
    //Encode in PEM format, the format prefered by openssl
//    if(false){
//      PEMWriter pemWriter=new PEMWriter(new FileWriter(localPrivateKeyFile));
//      pemWriter.writeObject(localPrivateECKey);
//      pemWriter.close();
//    }
//    else{
      String keyText = "-----BEGIN EC PRIVATE KEY-----\n" +
          Base64.encode(Unpooled.wrappedBuffer(localPrivateECKey.getEncoded()), true).toString(CharsetUtil.US_ASCII) +
          "\n-----END EC PRIVATE KEY-----\n";
      Files.write(keyText, localPrivateKeyFile, CharsetUtil.US_ASCII);

      Files.write(localId.toString(), new File(localPrivateKeyFile.getParentFile(), "localPublic.hash"), CharsetUtil.US_ASCII);
//    }

    PEMWriter certificateWriter=new PEMWriter(new FileWriter(localCertificateFile));
    certificateWriter.writeObject(cert);
    certificateWriter.close();
    LOGGER.info("Saved to "+localCertificateFile.getAbsolutePath());
  }
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:26,代码来源:NodeIdentity.java

示例2: encryptedTest

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的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

示例3: getPEMStringFromRSAKeyPair

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
/**
 * Converts RSA private key to PEM string.
 * 
 * @param rsaKeyPair
 * 
 * @return PEM string
 */
public static String getPEMStringFromRSAKeyPair(RSAKeyPair rsaKeyPair) {
    StringWriter pemStrWriter = new StringWriter();
    PEMWriter pemWriter = new PEMWriter(pemStrWriter);
    try {
        KeyPair keyPair = new KeyPair(rsaKeyPair.getPublic(), rsaKeyPair.getPrivate());
        //pemWriter.writeObject(keyPair);
        pemWriter.writeObject(keyPair.getPrivate());
        //pemWriter.flush();
        pemWriter.close();

    } catch (IOException e) {
        log.warning("Caught exception:" + e.getMessage());
        return "";
    }

    return pemStrWriter.toString();
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:25,代码来源:Encryption.java

示例4: writeCertificate

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private void writeCertificate(Certificate... certificates)
        throws IOException {
    final PEMWriter writer = new PEMWriter(new FileWriter(destfile));
    for (final Certificate c : certificates) {
        writer.writeObject(c);
    }
    writer.close();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:9,代码来源:SignTask.java

示例5: toPem

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private static String toPem(X509Certificate certificate) throws IOException {
	StringWriter stringWriter = new StringWriter();
	PEMWriter pemWriter = new PEMWriter(stringWriter, BouncyCastleProvider.PROVIDER_NAME);
	pemWriter.writeObject(certificate);
	pemWriter.close();
	return stringWriter.toString();
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:8,代码来源:JSONServlet.java

示例6: getPEM

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private String getPEM(Key key) {
    StringWriter sw = new StringWriter(1024);
    PEMWriter pw = new PEMWriter(sw);

    try {
        pw.writeObject(key);
        pw.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sw.getBuffer().toString();
}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:13,代码来源:RSAKeyCrypto.java

示例7: keyPairToString

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private String keyPairToString(KeyPair keyPair) {
	StringWriter stringWriter = new StringWriter();
	PEMWriter pemWriter = new PEMWriter(stringWriter);
	try {
		pemWriter.writeObject(keyPair);
		pemWriter.flush();
		pemWriter.close();
	} catch (IOException e) {
		throw new RuntimeException("Unexpected IOException: "
				+ e.getMessage(), e);
	}
	return stringWriter.getBuffer().toString();
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:14,代码来源:ScmKeyPairProvider.java

示例8: getPEMCertificate

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
@NotNull
public String getPEMCertificate(@NotNull String name, String alias) throws KeyStoreException, IOException {
  Certificate certificate = Optional.ofNullable(getKeyStore(name).getKeyStore().getCertificate(alias))
    .orElseThrow(() -> new IllegalArgumentException("Cannot find certificate for alias: " + alias));

  StringWriter writer = new StringWriter();
  PEMWriter pemWriter = new PEMWriter(writer);
  pemWriter.writeObject(certificate);
  pemWriter.flush();

  return writer.getBuffer().toString();
}
 
开发者ID:obiba,项目名称:agate,代码行数:13,代码来源:KeyStoreService.java

示例9: getInPemFormat

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private static String getInPemFormat(PrivateKey privateKey)
        throws IOException {
  final StringWriter stringWriter = new StringWriter();
  final PEMWriter pemWriter = new PEMWriter(stringWriter);
  pemWriter.writeObject(privateKey);
  pemWriter.flush();
  pemWriter.close();
  return stringWriter.toString();
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:10,代码来源:JsonServiceAccountConfigTestUtil.java

示例10: getPEMCertificate

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
@NotNull
public String getPEMCertificate(@NotNull String name, String alias) throws KeyStoreException, IOException {
  Certificate certificate = ofNullable(getKeyStore(name).getKeyStore().getCertificate(alias))
    .orElseThrow(() -> new IllegalArgumentException("Cannot find certificate for alias: " + alias));

  StringWriter writer = new StringWriter();
  PEMWriter pemWriter = new PEMWriter(writer);
  pemWriter.writeObject(certificate);
  pemWriter.flush();

  return writer.getBuffer().toString();
}
 
开发者ID:obiba,项目名称:mica2,代码行数:13,代码来源:KeyStoreService.java

示例11: writeKeyPair

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
public static String writeKeyPair(KeyPair kp) throws Exception {
    StringWriter stringWriter = new StringWriter();

    PEMWriter w = new PEMWriter(stringWriter);
    w.writeObject(kp);
    w.flush();
    IOUtils.closeQuietly(w);

    return stringWriter.toString();
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:11,代码来源:SshKeyGen.java

示例12: writeKeyPair

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
protected String writeKeyPair(KeyPair kp) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PEMWriter w = new PEMWriter(new OutputStreamWriter(baos));
    w.writeObject(kp);
    w.flush();
    IOUtils.closeQuietly(w);

    return Base64.encodeBase64String(baos.toByteArray());
}
 
开发者ID:ibuildthecloud,项目名称:dstack,代码行数:10,代码来源:ClientKeyPairProvider.java

示例13: getPemBytes

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
public byte[] getPemBytes(final Object o) throws IOException {
    LOG.debug(String.format("getPemBytes(%s)", o));
    ByteArrayOutputStream pemByteOut = new ByteArrayOutputStream();
    PEMWriter pemOut = new PEMWriter(new OutputStreamWriter(pemByteOut));
    pemOut.writeObject(o);
    pemOut.close();
    return pemByteOut.toByteArray();
}
 
开发者ID:barnyard,项目名称:pi,代码行数:9,代码来源:SecurityUtils.java

示例14: doWriteReadTest

import org.bouncycastle.openssl.PEMWriter; //导入方法依赖的package包/类
private void doWriteReadTest(
    PrivateKey  akp,
    String      provider)
    throws IOException
{
    StringWriter sw = new StringWriter();
    PEMWriter pw = new PEMWriter(sw, provider);

    pw.writeObject(akp);
    pw.close();

    String data = sw.toString();

    PEMReader pr = new PEMReader(new StringReader(data));

    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 (!akp.equals(privKey))
    {
        fail("Failed to read back test");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:31,代码来源:WriterTest.java

示例15: encryptedTestNew

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

    JceOpenSSLPKCS8EncryptorBuilder encryptorBuilder = new JceOpenSSLPKCS8EncryptorBuilder(algorithm);

    encryptorBuilder.setProvider("BC");
    encryptorBuilder.setPasssword("hello".toCharArray());

    PKCS8Generator pkcs8 = new JcaPKCS8Generator(key, encryptorBuilder.build());

    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,代码行数:30,代码来源:AllTests.java


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