當前位置: 首頁>>代碼示例>>Java>>正文


Java PrivateKeyInfo.getEncoded方法代碼示例

本文整理匯總了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!");
}
 
開發者ID:subshare,項目名稱:subshare,代碼行數:39,代碼來源:CryptoRegistry.java

示例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;
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:JDKDSAPrivateKey.java

示例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;
     }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:12,代碼來源:KeyUtil.java

示例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;
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:BCElGamalPrivateKey.java

示例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);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:30,代碼來源:PKCS8Generator.java

示例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;
    }
}
 
開發者ID:thedrummeraki,項目名稱:Aki-SSL,代碼行數:20,代碼來源:JDKDSAPrivateKey.java

示例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;
    }
}
 
開發者ID:thedrummeraki,項目名稱:Aki-SSL,代碼行數:20,代碼來源:BCElGamalPrivateKey.java


注:本文中的org.bouncycastle.asn1.pkcs.PrivateKeyInfo.getEncoded方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。