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


Java JcaPEMWriter.flush方法代码示例

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


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

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

示例2: encodeObjectAsPemString

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Encodes the specified security object in PEM format, using the specified encryptor. If the encryptor is null,
 * the object will not be encrypted in the generated String.
 *
 * @param object    object to encrypt (certificate, private key, etc.)
 * @param encryptor engine to encrypt the resulting PEM String, or null if no encryption should be used
 * @return a PEM-encoded String
 */
private static String encodeObjectAsPemString(Object object, PEMEncryptor encryptor) {
    StringWriter stringWriter = new StringWriter();

    try {
        JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter);
        pemWriter.writeObject(object, encryptor);
        pemWriter.flush();
    } catch (IOException e) {
        throw new ExportException("Unable to generate PEM string representing object", e);
    }

    return stringWriter.toString();
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:22,代码来源:BouncyCastleSecurityProviderTool.java

示例3: exportPEMObject

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Helper method for exporting PEM object.
 * 
 * @param object
 *            to export in PEM format.
 * @param filename
 *            for the file to export.
 */
public void exportPEMObject(Object pemObject, String filename) throws IOException {
	Writer writer;
	writer = new FileWriter(filename);
	JcaPEMWriter jcaPemWriter = new JcaPEMWriter(writer);
	jcaPemWriter.writeObject(pemObject);
	jcaPemWriter.flush();
	jcaPemWriter.close();
}
 
开发者ID:SAMLRaider,项目名称:SAMLRaider,代码行数:17,代码来源:FileHelper.java

示例4: writePublicKey

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static String writePublicKey(PublicKey pk) throws Exception {
    StringWriter stringWriter = new StringWriter();

    JcaPEMWriter w = new JcaPEMWriter(stringWriter);
    w.writeObject(pk);
    w.flush();
    IOUtils.closeQuietly(w);

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

示例5: write

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
protected void write(ZipOutputStream zos, String name, Object obj) throws IOException {
    ZipEntry ze = new ZipEntry(name);
    zos.putNextEntry(ze);
    JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(zos));
    writer.writeObject(obj);
    writer.flush();
    zos.closeEntry();
}
 
开发者ID:rancher,项目名称:cattle,代码行数:9,代码来源:CertSet.java

示例6: saveKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static void saveKeyPair(KeyPair pair, OutputStream keyfile)
		throws CertificateException {

	JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(keyfile));
	try {
		writer.writeObject(pair.getPrivate());
		writer.flush();
		writer.close();
	} catch (IOException e) {
		throw new CertificateException("Failed to save key pair", e);
	}
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:13,代码来源:X509CertificateUtils.java

示例7: saveCertificate

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static void saveCertificate(Certificate[] certs,
		OutputStream certfile) throws CertificateException {
	JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(certfile));

	try {
		for (Certificate c : certs) {
			writer.writeObject(c);
		}
		writer.flush();
		writer.close();
	} catch (IOException e) {
		throw new CertificateException("Failed to save certificate", e);
	}

}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:16,代码来源:X509CertificateUtils.java

示例8: exportPem

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
@AuthenticationRequired
@RequestMapping(value = "certificates/exportPem/{id}", method = RequestMethod.POST, produces = { "application/json" })
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public RequestStatus exportPem(HttpServletRequest request,
		HttpServletResponse response, @PathVariable Long id,
		@RequestParam(value = "passphrase") String passphrase)
		throws AccessDeniedException, UnauthorizedException,
		SessionTimeoutException {

	setupAuthenticatedContext(sessionUtils.getSession(request),
			sessionUtils.getLocale(request));

	try {
		CertificateStatus status = new CertificateStatus();
		status.setSuccess(false);
		try {

			CertificateResource resource = resourceService
					.getResourceById(id);

			ByteArrayOutputStream out = new ByteArrayOutputStream();
			ZipOutputStream zip = new ZipOutputStream(
					new BufferedOutputStream(out));

			zip.putNextEntry(new ZipEntry("certificate.pem"));
			zip.write(resource.getCertificate().getBytes("UTF-8"));
			zip.closeEntry();

			if (StringUtils.isNotEmpty(resource.getBundle())) {
				zip.putNextEntry(new ZipEntry("ca-bundle.pem"));
				zip.write(resource.getBundle().getBytes("UTF-8"));
				zip.closeEntry();
			}
			zip.putNextEntry(new ZipEntry("key.pem"));
			if (passphrase == null || passphrase.trim().equals("")) {
				zip.write(resource.getPrivateKey().getBytes("UTF-8"));
			} else {
				KeyPair keypair = X509CertificateUtils.loadKeyPairFromPEM(
						new ByteArrayInputStream(resource.getPrivateKey()
								.getBytes("UTF-8")), passphrase
								.toCharArray());
				ByteArrayOutputStream bout = new ByteArrayOutputStream();
				JcaPEMWriter pem = new JcaPEMWriter(
						new OutputStreamWriter(bout));
				pem.writeObject(
						keypair,
						new JcePEMEncryptorBuilder("AES-128-CBC")
								.setProvider("BC").build(
										passphrase.toCharArray()));
				pem.flush();
				zip.write(bout.toByteArray());
				pem.close();
				bout.close();
			}
			zip.closeEntry();
			zip.close();
			request.getSession().setAttribute("pem", out.toByteArray());
			return new RequestStatus(true);
		} catch (Exception e) {
			return new RequestStatus(false, e.getMessage());
		}
	} finally {
		clearAuthenticatedContext();
	}
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:67,代码来源:CertificateResourceController.java


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