本文整理汇总了Java中org.bouncycastle.asn1.pkcs.PrivateKeyInfo.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java PrivateKeyInfo.getEncoded方法的具体用法?Java PrivateKeyInfo.getEncoded怎么用?Java PrivateKeyInfo.getEncoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.pkcs.PrivateKeyInfo
的用法示例。
在下文中一共展示了PrivateKeyInfo.getEncoded方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodePrivateKey
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
/**
* <p>
* Encode (serialise) a private key in order to store it or transport it over a network.
* </p><p>
* <b>Important: You should keep your private key secret!</b> Thus, you might want to encrypt the result before
* storing it to a file or sending it somewhere!
* </p>
* @param privateKey the private key to be encoded; must not be <code>null</code>.
* @return the encoded (serialised) form of the private key. Can be passed to {@link #decodePrivateKey(byte[])} to
* reverse this method.
* @see #decodePrivateKey(byte[])
* @see #encodePublicKey(CipherParameters)
*/
public byte[] encodePrivateKey(final CipherParameters privateKey)
{
if (privateKey == null)
throw new IllegalArgumentException("privateKey == null");
// TODO use a class-based map or similar registry!
try {
if (privateKey instanceof RSAPrivateCrtKeyParameters) {
final RSAPrivateCrtKeyParameters rsaPrivateKey = (RSAPrivateCrtKeyParameters) privateKey;
final PrivateKeyInfo info = new PrivateKeyInfo(
new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
new RSAPrivateKey(
rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent(), rsaPrivateKey.getExponent(),
rsaPrivateKey.getP(), rsaPrivateKey.getQ(), rsaPrivateKey.getDP(),
rsaPrivateKey.getDQ(), rsaPrivateKey.getQInv()).toASN1Primitive()
);
return info.getEncoded();
}
} catch (final IOException x) {
throw new RuntimeException(x);
}
throw new UnsupportedOperationException("privateKey.class=\"" + privateKey.getClass().getName() + "\" not yet supported!");
}
示例2: getEncoded
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
/**
* Return a PKCS8 representation of the key. The sequence returned
* represents a full PrivateKeyInfo object.
*
* @return a PKCS8 representation of the key.
*/
public byte[] getEncoded()
{
try
{
PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG())), new DERInteger(getX()));
return info.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
return null;
}
}
示例3: getEncodedPrivateKeyInfo
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
public static byte[] getEncodedPrivateKeyInfo(PrivateKeyInfo info)
{
try
{
return info.getEncoded(ASN1Encoding.DER);
}
catch (Exception e)
{
return null;
}
}
示例4: getEncoded
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
/**
* Return a PKCS8 representation of the key. The sequence returned
* represents a full PrivateKeyInfo object.
*
* @return a PKCS8 representation of the key.
*/
public byte[] getEncoded()
{
try
{
PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new DERInteger(getX()));
return info.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
return null;
}
}
示例5: generate
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
private PemObject generate(PrivateKeyInfo key, OutputEncryptor encryptor)
throws PemGenerationException
{
try
{
byte[] keyData = key.getEncoded();
if (encryptor == null)
{
return new PemObject("PRIVATE KEY", keyData);
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream cOut = encryptor.getOutputStream(bOut);
cOut.write(key.getEncoded());
cOut.close();
EncryptedPrivateKeyInfo info = new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray());
return new PemObject("ENCRYPTED PRIVATE KEY", info.getEncoded());
}
catch (IOException e)
{
throw new PemGenerationException("unable to process encoded key data: " + e.getMessage(), e);
}
}
示例6: getEncoded
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
/**
* Return a PKCS8 representation of the key. The sequence returned
* represents a full PrivateKeyInfo object.
*
* @return a PKCS8 representation of the key.
*/
public byte[] getEncoded()
{
try
{
PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG())), new ASN1Integer(getX()));
return info.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
return null;
}
}
示例7: getEncoded
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; //导入方法依赖的package包/类
/**
* Return a PKCS8 representation of the key. The sequence returned
* represents a full PrivateKeyInfo object.
*
* @return a PKCS8 representation of the key.
*/
public byte[] getEncoded()
{
try
{
PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new ASN1Integer(getX()));
return info.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
return null;
}
}