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


Java PrivateKeyInfo类代码示例

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


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

示例1: readPrivateKey

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
/** Read a PKCS#8 format private key. */
private static PrivateKey readPrivateKey(InputStream input)
throws IOException, GeneralSecurityException {
    try {
        byte[] buffer = new byte[4096];
        int size = input.read(buffer);
        byte[] bytes = Arrays.copyOf(buffer, size);
        /* Check to see if this is in an EncryptedPrivateKeyInfo structure. */
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(bytes);
        /*
         * Now it's in a PKCS#8 PrivateKeyInfo structure. Read its Algorithm
         * OID and use that to construct a KeyFactory.
         */
        ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(spec.getEncoded()));
        PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
        String algOid = pki.getPrivateKeyAlgorithm().getAlgorithm().getId();
        return KeyFactory.getInstance(algOid).generatePrivate(spec);
    } finally {
        input.close();
    }
}
 
开发者ID:bhb27,项目名称:isu,代码行数:22,代码来源:ZipUtils.java

示例2: parseObject

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的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);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:PEMReader.java

示例3: PKIArchiveControlBuilder

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
/**
 * Basic constructor - specify the contents of the PKIArchiveControl structure.
 *
 * @param privateKeyInfo the private key to be archived.
 * @param generalName the general name to be associated with the private key.
 */
public PKIArchiveControlBuilder(PrivateKeyInfo privateKeyInfo, GeneralName generalName)
{
    EncKeyWithID encKeyWithID = new EncKeyWithID(privateKeyInfo, generalName);

    try
    {
        this.keyContent = new CMSProcessableByteArray(CRMFObjectIdentifiers.id_ct_encKeyWithID, encKeyWithID.getEncoded());
    }
    catch (IOException e)
    {
        throw new IllegalStateException("unable to encode key and general name info");
    }

    this.envGen = new CMSEnvelopedDataGenerator();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:PKIArchiveControlBuilder.java

示例4: decryptPrivateKeyInfo

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
public PrivateKeyInfo decryptPrivateKeyInfo(InputDecryptorProvider inputDecryptorProvider)
    throws PKCSException
{
    try
    {
        InputDecryptor decrytor = inputDecryptorProvider.get(encryptedPrivateKeyInfo.getEncryptionAlgorithm());

        ByteArrayInputStream encIn = new ByteArrayInputStream(encryptedPrivateKeyInfo.getEncryptedData());

        return PrivateKeyInfo.getInstance(Streams.readAll(decrytor.getInputStream(encIn)));
    }
    catch (Exception e)
    {
        throw new PKCSException("unable to read encrypted data: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:PKCS8EncryptedPrivateKeyInfo.java

示例5: EncKeyWithID

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
private EncKeyWithID(ASN1Sequence seq)
{
    this.privKeyInfo = PrivateKeyInfo.getInstance(seq.getObjectAt(0));

    if (seq.size() > 1)
    {
        if (!(seq.getObjectAt(1) instanceof DERUTF8String))
        {
            this.identifier = GeneralName.getInstance(seq.getObjectAt(1));
        }
        else
        {
            this.identifier = (ASN1Encodable)seq.getObjectAt(1);
        }
    }
    else
    {
        this.identifier = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:EncKeyWithID.java

示例6: engineGeneratePrivate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof PKCS8EncodedKeySpec)
    {
        try
        {
            PrivateKeyInfo info = PrivateKeyInfo.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded());
            PrivateKey     key = BouncyCastleProvider.getPrivateKey(info);

            if (key != null)
            {
                return key;
            }

            throw new InvalidKeySpecException("no factory found for OID: " + info.getPrivateKeyAlgorithm().getAlgorithm());
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    }

    throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:KeyFactory.java

示例7: BCGOST3410PrivateKey

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];
    
    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }
    
    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:BCGOST3410PrivateKey.java

示例8: generatePrivate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo)
    throws IOException
{
    ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm();

    if (algOid.equals(PKCSObjectIdentifiers.dhKeyAgreement))
    {
        return new BCDHPrivateKey(keyInfo);
    }
    else if (algOid.equals(X9ObjectIdentifiers.dhpublicnumber))
    {
        return new BCDHPrivateKey(keyInfo);
    }
    else
    {
        throw new IOException("algorithm identifier " + algOid + " in key not recognised");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:19,代码来源:KeyFactorySpi.java

示例9: engineGeneratePrivate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof PKCS8EncodedKeySpec)
    {
        try
        {
            return generatePrivate(PrivateKeyInfo.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded()));
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException("encoded key spec not recognised");
        }
    }
    else
    {
        throw new InvalidKeySpecException("key spec not recognised");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:BaseKeyFactorySpi.java

示例10: generatePrivate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
public PrivateKey generatePrivate(PrivateKeyInfo info)
    throws IOException
{
    ASN1ObjectIdentifier algOid = info.getPrivateKeyAlgorithm().getAlgorithm();

    if (algOid.equals(PKCSObjectIdentifiers.dhKeyAgreement))
    {
        return new BCElGamalPrivateKey(info);
    }
    else if (algOid.equals(X9ObjectIdentifiers.dhpublicnumber))
    {
        return new BCElGamalPrivateKey(info);
    }
    else if (algOid.equals(OIWObjectIdentifiers.elGamalAlgorithm))
    {
        return new BCElGamalPrivateKey(info);
    }
    else
    {
        throw new IOException("algorithm identifier " + algOid + " in key not recognised");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:KeyFactorySpi.java

示例11: getPrivateKey

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的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

示例12: generate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
static PrivateKey generate(Path path) throws IOException {
    try (Reader in = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
        PEMParser parser = new PEMParser(in);

        Object keyPair = parser.readObject();
        if (!(keyPair instanceof PEMKeyPair)) {
            throw new IllegalStateException(String.format("%s contains an artifact that is not a key pair: %s", path, keyPair));
        }

        PrivateKeyInfo privateKeyInfo = ((PEMKeyPair) keyPair).getPrivateKeyInfo();
        if (privateKeyInfo == null) {
            throw new IllegalStateException(String.format("%s does not contain a private key", path));
        }

        return CONVERTER.getPrivateKey(privateKeyInfo);
    }
}
 
开发者ID:cloudfoundry,项目名称:java-buildpack-security-provider,代码行数:18,代码来源:PrivateKeyFactory.java

示例13: readPrivateKey

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
/**
 * Reads a base64-format PEM key and returns a Java PrivateKey for it.
 * @param privateKey PEM-encoded private key
 */
public static PrivateKey readPrivateKey(String privateKey) {
    try (StringReader keyReader = new StringReader(privateKey);
         PEMParser pemReader = new PEMParser(keyReader)) {
        
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object keyPair = pemReader.readObject();
        if (keyPair instanceof PrivateKeyInfo) {
            return converter.getPrivateKey((PrivateKeyInfo) keyPair);
        } else {
            return converter.getPrivateKey(((PEMKeyPair) keyPair).getPrivateKeyInfo());
        }
    } catch (IOException x) {
        // Shouldn't occur, since we're only reading from strings
        throw new RuntimeException(x);            
    }
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:21,代码来源:SSLFactory.java

示例14: getPrivateKeyFromPEM

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
private static PrivateKey getPrivateKeyFromPEM(final Reader keyReader)
  throws IOException {
  final JcaPEMKeyConverter jcaPEMKeyConverter = new JcaPEMKeyConverter();

  final PEMParser pem = new PEMParser(keyReader);

  PrivateKey key;
  Object pemContent = pem.readObject();
  if(pemContent instanceof PEMKeyPair) {
    PEMKeyPair pemKeyPair = (PEMKeyPair)pemContent;
    KeyPair keyPair = jcaPEMKeyConverter.getKeyPair(pemKeyPair);
    key = keyPair.getPrivate();
  } else if (pemContent instanceof PrivateKeyInfo) {
    PrivateKeyInfo privateKeyInfo = (PrivateKeyInfo) pemContent;
    key = jcaPEMKeyConverter.getPrivateKey(privateKeyInfo);
  } else {
    throw new IllegalArgumentException("Unsupported private key format '" + pemContent.getClass().getSimpleName() + '"');
  }

  pem.close();
  return key;
}
 
开发者ID:heroku,项目名称:env-keystore,代码行数:23,代码来源:EnvKeyStore.java

示例15: generatePrivate

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入依赖的package包/类
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo)
    throws IOException
{
    ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm();

    if (RSAUtil.isRsaOid(algOid))
    {
        RSAPrivateKey rsaPrivKey = RSAPrivateKey.getInstance(keyInfo.parsePrivateKey());

        if (rsaPrivKey.getCoefficient().intValue() == 0)
        {
            return new BCRSAPrivateKey(rsaPrivKey);
        }
        else
        {
            return new BCRSAPrivateCrtKey(keyInfo);
        }
    }
    else
    {
        throw new IOException("algorithm identifier " + algOid + " in key not recognised");
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:24,代码来源:KeyFactorySpi.java


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