本文整理汇总了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();
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例13: JcaPKIArchiveControlBuilder
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKIArchiveControlBuilder(PrivateKey privateKey, GeneralName generalName)
{
super(PrivateKeyInfo.getInstance(privateKey.getEncoded()), generalName);
}
示例14: JcaPKCS8EncryptedPrivateKeyInfoBuilder
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKCS8EncryptedPrivateKeyInfoBuilder(PrivateKey privateKey)
{
super(PrivateKeyInfo.getInstance(privateKey.getEncoded()));
}
示例15: JcaPKCS12SafeBagBuilder
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public JcaPKCS12SafeBagBuilder(PrivateKey privateKey, OutputEncryptor encryptor)
{
super(PrivateKeyInfo.getInstance(privateKey.getEncoded()), encryptor);
}