當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。