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


Java PEMException类代码示例

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


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

示例1: getKeyPair

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public KeyPair getKeyPair(PEMKeyPair keyPair)
    throws PEMException
{
    try
    {
        String algorithm =  keyPair.getPrivateKeyInfo().getPrivateKeyAlgorithm().getAlgorithm().getId();

        if (X9ObjectIdentifiers.id_ecPublicKey.getId().equals(algorithm))
        {
            algorithm = "ECDSA";
        }

        KeyFactory keyFactory = helper.createKeyFactory(algorithm);

        return new KeyPair(keyFactory.generatePublic(new X509EncodedKeySpec(keyPair.getPublicKeyInfo().getEncoded())),
                            keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyPair.getPrivateKeyInfo().getEncoded())));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:JcaPEMKeyConverter.java

示例2: getPublicKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo)
    throws PEMException
{
    try
    {
        String algorithm =  publicKeyInfo.getAlgorithm().getAlgorithm().getId();

        if (X9ObjectIdentifiers.id_ecPublicKey.getId().equals(algorithm))
        {
            algorithm = "ECDSA";
        }

        KeyFactory keyFactory = helper.createKeyFactory(algorithm);

        return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyInfo.getEncoded()));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:JcaPEMKeyConverter.java

示例3: getPrivateKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PrivateKey getPrivateKey(PrivateKeyInfo privateKeyInfo)
    throws PEMException
{
    try
    {
        String algorithm =  privateKeyInfo.getPrivateKeyAlgorithm().getAlgorithm().getId();

        if (X9ObjectIdentifiers.id_ecPublicKey.getId().equals(algorithm))
        {
            algorithm = "ECDSA";
        }

        KeyFactory keyFactory = helper.createKeyFactory(algorithm);

        return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(privateKeyInfo.getEncoded()));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:JcaPEMKeyConverter.java

示例4: build

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PEMDecryptorProvider build(final char[] password)
{
    return new PEMDecryptorProvider()
    {
        public PEMDecryptor get(final String dekAlgName)
        {
            return new PEMDecryptor()
            {
                public byte[] decrypt(byte[] keyBytes, byte[] iv)
                    throws PEMException
                {
                    if (password == null)
                    {
                        throw new PasswordException("Password is null, but a password is required");
                    }

                    return PEMUtilities.crypt(false, helper, keyBytes, password, dekAlgName, iv);
                }
            };
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:JcePEMDecryptorProviderBuilder.java

示例5: getKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
private static KeyParameter getKey(
    char[]  password,
    int     keyLength,
    byte[]  salt,
    boolean des2)
    throws PEMException
{
    PBEParametersGenerator paramsGen = new OpenSSLPBEParametersGenerator();

    paramsGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, 1);

    KeyParameter kp = (KeyParameter)paramsGen.generateDerivedParameters(keyLength * 8);

    if (des2 && kp.getKey().length == 24)
    {
        // For DES2, we must copy first 8 bytes into the last 8 bytes.
        byte[] key = kp.getKey();

        System.arraycopy(key, 0, key, 16, 8);

        return new KeyParameter(key);
    }

    return kp;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:26,代码来源:PEMUtilities.java

示例6: get

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PEMDecryptor get(final String dekAlgName)
{
    return new PEMDecryptor()
    {
        public byte[] decrypt(byte[] keyBytes, byte[] iv)
            throws PEMException
        {
            if (password == null)
            {
                throw new PasswordException("Password is null, but a password is required");
            }

            return PEMUtilities.crypt(false, keyBytes, password, dekAlgName, iv);
        }
    };
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:17,代码来源:BcPEMDecryptorProvider.java

示例7: providePrivateKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
@Singleton
@Provides
static PrivateKey providePrivateKey(@Named("pemObjects") ImmutableList<Object> pemObjects) {
  JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
  Function<PEMKeyPair, PrivateKey> privateKeyConverter =
      pemKeyPair -> {
        try {
          return converter.getKeyPair(pemKeyPair).getPrivate();
        } catch (PEMException e) {
          logger.severefmt(e, "Error converting private key: %s", pemKeyPair);
          throw new RuntimeException(e);
        }
      };
  ImmutableList<PrivateKey> privateKeys =
      filterAndConvert(pemObjects, PEMKeyPair.class, privateKeyConverter);
  checkState(
      privateKeys.size() == 1,
      "The pem file must contain exactly one private key, but %s keys are found",
      privateKeys.size());
  return privateKeys.get(0);
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:CertificateModule.java

示例8: signCertificateRequest

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
/**
 * This method signs a certificate signing request (CSR) using the specified certificate
 * authority (CA).   This is a convenience method that really should be part of the
 * <code>CertificateManagement</code> interface except that it depends on a Bouncy Castle
 * class in the signature.  The java security framework does not have a similar class so it
 * has been left out of the interface.
 *
 * @param caPrivateKey The private key for the certificate authority.
 * @param caCertificate The certificate containing the public key for the certificate authority.
 * @param request The certificate signing request (CSR) to be signed.
 * @param serialNumber The serial number for the new certificate.
 * @param lifetime How long the certificate should be valid.
 *
 * @return The newly signed certificate.
 */
public X509Certificate signCertificateRequest(PrivateKey caPrivateKey, X509Certificate caCertificate,
        PKCS10CertificationRequest request, BigInteger serialNumber, long lifetime) {
    try {
        logger.entry();

        logger.debug("Extract public key and subject from the CSR...");
        PublicKey publicKey = new JcaPEMKeyConverter().getPublicKey(request.getSubjectPublicKeyInfo());
        String subject = request.getSubject().toString();

        logger.debug("Generate and sign the certificate...");
        X509Certificate result = createCertificate(caPrivateKey, caCertificate, publicKey, subject, serialNumber, lifetime);

        logger.exit();
        return result;

    } catch (PEMException e) {
        RuntimeException exception = new RuntimeException("An unexpected exception occurred while attempting to sign a certificate.", e);
        logger.error(exception.toString());
        throw exception;
    }
}
 
开发者ID:craterdog,项目名称:java-security-framework,代码行数:37,代码来源:RsaCertificateManager.java

示例9: tryParsePKCS8PemPrivateKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
private Key tryParsePKCS8PemPrivateKey(File pKeyFile) throws FileNotFoundException, IOException, PEMException {
    LOG.info("Trying to parse as PKCS8 private key file:" + pKeyFile.getName());

    Key internalKey;
    try (BufferedReader br = new BufferedReader(new FileReader(pKeyFile));
            PEMParser pp = new PEMParser(br);) {
        PrivateKeyInfo pkInfo = (PrivateKeyInfo) pp.readObject();
        internalKey = new JcaPEMKeyConverter().getPrivateKey(pkInfo);
    }

    return internalKey;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:13,代码来源:X509TrustManagerFactory.java

示例10: getKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
private static SecretKey getKey(
    JcaJceHelper helper,
    char[]  password,
    String  algorithm,
    int     keyLength,
    byte[]  salt)
    throws PEMException
{
    return getKey(helper, password, algorithm, keyLength, salt, false);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:11,代码来源:PEMUtilities.java

示例11: getKeyPair

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public KeyPair getKeyPair(PEMKeyPair keyPair)
    throws PEMException
{
    try
    {
        KeyFactory keyFactory = getKeyFactory(keyPair.getPrivateKeyInfo().getPrivateKeyAlgorithm());

        return new KeyPair(keyFactory.generatePublic(new X509EncodedKeySpec(keyPair.getPublicKeyInfo().getEncoded())),
                            keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyPair.getPrivateKeyInfo().getEncoded())));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:16,代码来源:JcaPEMKeyConverter.java

示例12: getPublicKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo)
    throws PEMException
{
    try
    {
        KeyFactory keyFactory = getKeyFactory(publicKeyInfo.getAlgorithm());

        return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyInfo.getEncoded()));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:15,代码来源:JcaPEMKeyConverter.java

示例13: getPrivateKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PrivateKey getPrivateKey(PrivateKeyInfo privateKeyInfo)
    throws PEMException
{
    try
    {
        KeyFactory keyFactory = getKeyFactory(privateKeyInfo.getPrivateKeyAlgorithm());

        return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(privateKeyInfo.getEncoded()));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:15,代码来源:JcaPEMKeyConverter.java

示例14: build

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public PEMEncryptor build(final char[] password)
{
    if (random == null)
    {
        random = new SecureRandom();
    }

    int ivLength = algorithm.startsWith("AES-") ? 16 : 8;

    final byte[] iv = new byte[ivLength];

    random.nextBytes(iv);

    return new PEMEncryptor()
    {
        public String getAlgorithm()
        {
            return algorithm;
        }

        public byte[] getIV()
        {
            return iv;
        }

        public byte[] encrypt(byte[] encoding)
            throws PEMException
        {
            return PEMUtilities.crypt(true, helper, encoding, password, algorithm, iv);
        }
    };
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:33,代码来源:JcePEMEncryptorBuilder.java

示例15: extractX509CSRPublicKey

import org.bouncycastle.openssl.PEMException; //导入依赖的package包/类
public static String extractX509CSRPublicKey(PKCS10CertificationRequest certReq) {
    
    JcaPEMKeyConverter pemConverter = new JcaPEMKeyConverter();
    PublicKey publicKey = null;
    try {
        publicKey = pemConverter.getPublicKey(certReq.getSubjectPublicKeyInfo());
    } catch (PEMException ex) {
        LOG.error("extractX509CSRPublicKey: unable to get public key: {}", ex.getMessage());
        return null;
    }

    return convertToPEMFormat(publicKey);
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:14,代码来源:Crypto.java


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