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


Java PrivateKeyInfo.getInstance方法代码示例

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


在下文中一共展示了PrivateKeyInfo.getInstance方法的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: 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

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

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

示例6: parseObject

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public Object parseObject(PemObject obj)
    throws IOException
{
    try
    {
        return PrivateKeyInfo.getInstance(obj.getContent());
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing PRIVATE KEY: " + e.toString(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:PEMParser.java

示例7: init

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
private void init(PrivateKey key, ASN1ObjectIdentifier algorithm, Provider provider)
    throws NoSuchAlgorithmException
{
    this.key = PrivateKeyInfo.getInstance(key.getEncoded());
    this.encryptorBuilder = new JceOpenSSLPKCS8EncryptorBuilder(algorithm);

    encryptorBuilder.setProvider(provider);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:9,代码来源:PKCS8Generator.java

示例8: encrypt

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
PKCS8EncryptedPrivateKeyInfo encrypt(PrivateKey privateKey) {
    ParamUtil.requireNonNull("privateKey", privateKey);
    PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(privateKey.getEncoded());
    PKCS8EncryptedPrivateKeyInfoBuilder builder = new PKCS8EncryptedPrivateKeyInfoBuilder(
            privateKeyInfo);
    synchronized (encryptor) {
        return builder.build(encryptor);
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:10,代码来源:PrivateKeyCryptor.java

示例9: getPrivateKeyInfo

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
private static PrivateKeyInfo getPrivateKeyInfo(PrivateKey privateKey)
{
     try
     {
         return PrivateKeyInfo.getInstance(privateKey.getEncoded());
     }
     catch (Exception e)             // for a HSM getEncoded() may do anything...
     {
         return null;
     }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:12,代码来源:JcaPKIXIdentity.java

示例10: getPrivateKey

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public ECPrivateKey getPrivateKey() throws IOException {
	ASN1Sequence pkSeq = null;
	pkSeq = (ASN1Sequence) ASN1Sequence.fromByteArray(pkBytes);
	
	PrivateKeyInfo pkInfo = PrivateKeyInfo.getInstance(pkSeq);
	ECPrivateKey ecpk = ECPrivateKey.getInstance(pkInfo.parsePrivateKey());
	return ecpk;
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:9,代码来源:CertificateProvider.java

示例11: testKeyConversion

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
private void testKeyConversion()
    throws Exception
{
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("ECDSA", "BC");

    kpGen.initialize(new ECGenParameterSpec("prime192v1"));

    KeyPair pair = kpGen.generateKeyPair();

    PublicKey pubKey = ECKeyUtil.publicToExplicitParameters(pair.getPublic(), "BC");

    SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(pubKey.getEncoded()));
    X962Parameters params = X962Parameters.getInstance(info.getAlgorithmId().getParameters());

    if (params.isNamedCurve() || params.isImplicitlyCA())
    {
        fail("public key conversion to explicit failed");
    }

    if (!((ECPublicKey)pair.getPublic()).getW().equals(((ECPublicKey)pubKey).getW()))
    {
        fail("public key conversion check failed");
    }

    PrivateKey privKey = ECKeyUtil.privateToExplicitParameters(pair.getPrivate(), "BC");
    PrivateKeyInfo privInfo = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(privKey.getEncoded()));
    params = X962Parameters.getInstance(privInfo.getAlgorithmId().getParameters());

    if (params.isNamedCurve() || params.isImplicitlyCA())
    {
        fail("private key conversion to explicit failed");
    }

    if (!((ECPrivateKey)pair.getPrivate()).getS().equals(((ECPrivateKey)privKey).getS()))
    {
        fail("private key conversion check failed");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:39,代码来源:ECDSA5Test.java

示例12: testNamedCurveParameterPreservation

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
private void testNamedCurveParameterPreservation()
    throws Exception
{
    AlgorithmParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
    KeyPairGenerator keygen = KeyPairGenerator.getInstance("EC", "BC");
    keygen.initialize(ecSpec, new ECRandom());

    KeyPair keys = keygen.generateKeyPair();

    PrivateKeyInfo priv1 = PrivateKeyInfo.getInstance(keys.getPrivate().getEncoded());
    SubjectPublicKeyInfo pub1 = SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded());

    keygen = KeyPairGenerator.getInstance("EC", "BC");
    keygen.initialize(new ECGenParameterSpec("secp256r1"), new ECRandom());

    PrivateKeyInfo priv2 = PrivateKeyInfo.getInstance(keys.getPrivate().getEncoded());
    SubjectPublicKeyInfo pub2 = SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded());

    if (!priv1.equals(priv2) || !pub1.equals(pub2))
    {
        fail("mismatch between alg param spec and ECGenParameterSpec");
    }

    if (!(priv2.getPrivateKeyAlgorithm().getParameters() instanceof ASN1ObjectIdentifier))
    {
        fail("OID not preserved in private key");
    }

    if (!(pub1.getAlgorithm().getParameters() instanceof ASN1ObjectIdentifier))
    {
        fail("OID not preserved in public key");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:34,代码来源:ECDSA5Test.java

示例13: JcaPKIArchiveControlBuilder

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKIArchiveControlBuilder(PrivateKey privateKey, GeneralName generalName)
{
    super(PrivateKeyInfo.getInstance(privateKey.getEncoded()), generalName);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:JcaPKIArchiveControlBuilder.java

示例14: JcaPKCS8EncryptedPrivateKeyInfoBuilder

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKCS8EncryptedPrivateKeyInfoBuilder(PrivateKey privateKey)
{
     super(PrivateKeyInfo.getInstance(privateKey.getEncoded()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:JcaPKCS8EncryptedPrivateKeyInfoBuilder.java

示例15: JcaPKCS12SafeBagBuilder

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKCS12SafeBagBuilder(PrivateKey privateKey, OutputEncryptor encryptor)
{
    super(PrivateKeyInfo.getInstance(privateKey.getEncoded()), encryptor);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:JcaPKCS12SafeBagBuilder.java


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