本文整理汇总了Java中org.bouncycastle.util.io.pem.PemObject.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java PemObject.getContent方法的具体用法?Java PemObject.getContent怎么用?Java PemObject.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.io.pem.PemObject
的用法示例。
在下文中一共展示了PemObject.getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPrivateKeyFromPemFile
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private static PrivateKey createPrivateKeyFromPemFile(final String keyFileName) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException
{
// Loads a privte key from the specified key file name
final PemReader pemReader = new PemReader(new FileReader(keyFileName));
final PemObject pemObject = pemReader.readPemObject();
final byte[] pemContent = pemObject.getContent();
pemReader.close();
final PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(pemContent);
final KeyFactory keyFactory = getKeyFactoryInstance();
final PrivateKey privateKey = keyFactory.generatePrivate(encodedKeySpec);
return privateKey;
}
开发者ID:PacktPublishing,项目名称:MQTT-Essentials-A-Lightweight-IoT-Protocol,代码行数:13,代码来源:SecurityHelper.java
示例2: parseObject
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public Object parseObject(PemObject obj)
throws IOException
{
try
{
PrivateKeyInfo info = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(obj.getContent()));
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(obj.getContent());
KeyFactory keyFact = KeyFactory.getInstance(info.getPrivateKeyAlgorithm().getAlgorithm().getId(), provider);
return keyFact.generatePrivate(keySpec);
}
catch (Exception e)
{
throw new PEMException("problem parsing PRIVATE KEY: " + e.toString(), e);
}
}
示例3: convert
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static ByteArrayOutputStream convert(final ByteArrayOutputStream baos) {
try (ByteArrayOutputStream autoCloseableBaos = baos;
ByteArrayInputStream bais = new ByteArrayInputStream(autoCloseableBaos.toByteArray());
Reader reader = new InputStreamReader(bais);
PemReader pemReader = new PemReader(reader)) {
PemObject pemObject = pemReader.readPemObject();
if (pemObject == null) {
throw new DSSException("Unable to read PEM Object");
}
byte[] binaries = pemObject.getContent();
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write(binaries, 0, binaries.length);
return os;
} catch (IOException e) {
throw new DSSException("Unable to convert the CRL to DER", e);
}
}
示例4: parseChain
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static List<Certificate> parseChain(final String chain) throws IOException, CertificateException {
Preconditions.checkNotNull(chain);
final List<Certificate> certs = new ArrayList<Certificate>();
try(final PemReader pemReader = new PemReader(new StringReader(chain));)
{
final PemObject pemObject = pemReader.readPemObject();
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
final ByteArrayInputStream bais = new ByteArrayInputStream(pemObject.getContent());
for (final Certificate cert : certificateFactory.generateCertificates(bais)) {
if (cert instanceof X509Certificate) {
certs.add(cert);
}
}
if (certs.isEmpty()) {
throw new IllegalStateException("Unable to decode certificate chain");
}
}
return certs;
}
示例5: parseObject
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
* Reads in a X509Certificate.
*
* @return the X509Certificate
* @throws IOException if an I/O error occured
*/
public Object parseObject(PemObject obj)
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());
try
{
CertificateFactory certFact
= CertificateFactory.getInstance("X.509", provider);
return certFact.generateCertificate(bIn);
}
catch (Exception e)
{
throw new PEMException("problem parsing cert: " + e.toString(), e);
}
}
示例6: parseObject
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
* Reads in a X509CRL.
*
* @return the X509Certificate
* @throws IOException if an I/O error occured
*/
public Object parseObject(PemObject obj)
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());
try
{
CertificateFactory certFact
= CertificateFactory.getInstance("X.509", provider);
return certFact.generateCRL(bIn);
}
catch (Exception e)
{
throw new PEMException("problem parsing cert: " + e.toString(), e);
}
}
示例7: getSocketFactoryFromPEM
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private SSLSocketFactory getSocketFactoryFromPEM(String filePath) throws Exception {
Security.addProvider(new BouncyCastleProvider());
PEMParser pemParser = new PEMParser(new FileReader(getConfigFilename(filePath)));
pemParser.readObject();
PemObject pemObject = pemParser.readPemObject();
pemParser.close();
X509CertificateHolder holder = new X509CertificateHolder(pemObject.getContent());
X509Certificate bc = new JcaX509CertificateConverter().setProvider("BC")
.getCertificate(holder);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", bc);
TrustManager trustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
SSLContext sslContext = SSLContextUtils.createSSLContext("TLS", null, trustManager);
return sslContext.getSocketFactory();
}
示例8: parseObject
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
* Reads in a X509Certificate.
*
* @return the X509Certificate
* @throws java.io.IOException if an I/O error occured
*/
public Object parseObject(PemObject obj)
throws IOException
{
try
{
return new X509CertificateHolder(obj.getContent());
}
catch (Exception e)
{
throw new PEMException("problem parsing cert: " + e.toString(), e);
}
}
示例9: parsePEMFile
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private static byte[] parsePEMFile(File pemFile) throws IOException {
if (!pemFile.isFile() || !pemFile.exists()) {
throw new FileNotFoundException(String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath()));
}
PemReader reader = new PemReader(new FileReader(pemFile));
PemObject pemObject = reader.readPemObject();
byte[] content = pemObject.getContent();
reader.close();
return content;
}
示例10: readRsaPrivateKey
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static RSAPrivateKey readRsaPrivateKey(Reader reader) {
Security.addProvider(new BouncyCastleProvider());
try {
KeyFactory factory = KeyFactory.getInstance("RSA", "BC");
PemReader pemReader = new PemReader(reader);
PemObject privatePem = pemReader.readPemObject();
PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privatePem.getContent());
RSAPrivateKey privateKey = (RSAPrivateKey) factory.generatePrivate(privateSpec);
return privateKey;
} catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException e) {
throw new RuntimeException("Unable to extract private RAS Key .", e);
}
}
示例11: certificateToDER
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public byte[] certificateToDER(String certificatePEM) {
byte[] content = null;
try (PemReader pemReader = new PemReader(new StringReader(certificatePEM))) {
final PemObject pemObject = pemReader.readPemObject();
content = pemObject.getContent();
} catch (IOException e) {
// best attempt
}
return content;
}
示例12: getPemPrivateKey
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static PrivateKey getPemPrivateKey(String filename, String algorithm) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(filename));
Security.addProvider(new BouncyCastleProvider());
PemReader pp = new PemReader(br);
PemObject pem = pp.readPemObject();
byte[] content = pem.getContent();
pp.close();
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(content);
KeyFactory kf = KeyFactory.getInstance(algorithm);
return kf.generatePrivate(spec);
}
示例13: getPemPublicKey
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
public static PublicKey getPemPublicKey(String filename, String algorithm) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(filename));
Security.addProvider(new BouncyCastleProvider());
PemReader pp = new PemReader(br);
PemObject pem = pp.readPemObject();
byte[] content = pem.getContent();
pp.close();
X509EncodedKeySpec spec =
new X509EncodedKeySpec(content);
KeyFactory kf = KeyFactory.getInstance(algorithm);
return kf.generatePublic(spec);
}
示例14: certFromString
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
private X509Certificate certFromString(String pem) throws Exception {
PemObject pemObject = (PemObject) readPemObject(pem);
ByteArrayInputStream inputStream= new ByteArrayInputStream(pemObject.getContent());
try {
CertificateFactory certFact = CertificateFactory.getInstance("X.509");
return (X509Certificate) certFact.generateCertificate(inputStream);
} catch (CertificateException e) {
throw new Exception("problem parsing cert: " + e.toString(),e);
}
}
示例15: convertToDER
import org.bouncycastle.util.io.pem.PemObject; //导入方法依赖的package包/类
/**
* This method converts a PEM encoded certificate/crl/... to DER encoded
*
* @param pemContent
* the String which contains the PEM encoded object
* @return the binaries of the DER encoded object
*/
public static byte[] convertToDER(String pemContent) {
try (Reader reader = new StringReader(pemContent); PemReader pemReader = new PemReader(reader)) {
PemObject readPemObject = pemReader.readPemObject();
return readPemObject.getContent();
} catch (IOException e) {
throw new DSSException("Unable to convert PEM to DER", e);
}
}