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


Java PEMWriter类代码示例

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


PEMWriter类属于org.bouncycastle.openssl包,在下文中一共展示了PEMWriter类的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: toPem

import org.bouncycastle.openssl.PEMWriter; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static byte[] toPem(Object object) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try (PEMWriter writer = new PEMWriter(new OutputStreamWriter(outputStream))) {
        writer.writeObject(object);
        writer.flush();
        return outputStream.toByteArray();
    }
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:10,代码来源:CertUtil.java

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

示例6: x509CertificateToPem

import org.bouncycastle.openssl.PEMWriter; //导入依赖的package包/类
public String x509CertificateToPem(final X509Certificate cert) throws IOException {
    final StringWriter sw = new StringWriter();
    try (final PEMWriter pw = new PEMWriter(sw)) {
        pw.writeObject(cert);
    }
    return sw.toString();
}
 
开发者ID:shapeblue,项目名称:ccs,代码行数:8,代码来源:ContainerClusterManagerImpl.java

示例7: rsaPrivateKeyToPem

import org.bouncycastle.openssl.PEMWriter; //导入依赖的package包/类
public String rsaPrivateKeyToPem(final PrivateKey key) throws IOException {
    final PemObject pemObject = new PemObject(CCS_RSA_PRIVATE_KEY, key.getEncoded());
    final StringWriter sw = new StringWriter();
    try (final PEMWriter pw = new PEMWriter(sw)) {
        pw.writeObject(pemObject);
    }
    return sw.toString();
}
 
开发者ID:shapeblue,项目名称:ccs,代码行数:9,代码来源:ContainerClusterManagerImpl.java

示例8: getPemBytes

import org.bouncycastle.openssl.PEMWriter; //导入依赖的package包/类
private static byte[] getPemBytes(Object... objects) throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  try (PEMWriter pemWriter =
      new PEMWriter(new OutputStreamWriter(byteArrayOutputStream, UTF_8))) {
    for (Object object : objects) {
      pemWriter.writeObject(object);
    }
  }
  return byteArrayOutputStream.toByteArray();
}
 
开发者ID:google,项目名称:nomulus,代码行数:11,代码来源:CertificateModuleTest.java

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

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

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

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

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

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

示例15: convertToPEMString

import org.bouncycastle.openssl.PEMWriter; //导入依赖的package包/类
public String convertToPEMString(X509Certificate x509Cert) throws IOException {

   StringWriter sw = new StringWriter();
   try (PEMWriter pw = new PEMWriter(sw)) {
       pw.writeObject(x509Cert);
   }
   
   return sw.toString();
 }
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:10,代码来源:EbicsCertificateService.java


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