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


Java DEROutputStream类代码示例

本文整理汇总了Java中org.bouncycastle.asn1.DEROutputStream的典型用法代码示例。如果您正苦于以下问题:Java DEROutputStream类的具体用法?Java DEROutputStream怎么用?Java DEROutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DEROutputStream类属于org.bouncycastle.asn1包,在下文中一共展示了DEROutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateSignatureBlock

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
private static byte[] generateSignatureBlock(
        SignerConfig signerConfig, byte[] signatureFileBytes)
                throws InvalidKeyException, CertificateEncodingException, SignatureException {
    JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
    X509Certificate signerCert = signerConfig.certificates.get(0);
    String jcaSignatureAlgorithm =
            getJcaSignatureAlgorithm(
                    signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
    try {
        ContentSigner signer =
                new JcaContentSignerBuilder(jcaSignatureAlgorithm)
                .build(signerConfig.privateKey);
        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
        gen.addSignerInfoGenerator(
                new SignerInfoGeneratorBuilder(
                        new JcaDigestCalculatorProviderBuilder().build(),
                        SignerInfoSignatureAlgorithmFinder.INSTANCE)
                        .setDirectSignature(true)
                        .build(signer, new JcaX509CertificateHolder(signerCert)));
        gen.addCertificates(certs);

        CMSSignedData sigData =
                gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
            DEROutputStream dos = new DEROutputStream(out);
            dos.writeObject(asn1.readObject());
        }
        return out.toByteArray();
    } catch (OperatorCreationException | CMSException | IOException e) {
        throw new SignatureException("Failed to generate signature", e);
    }
}
 
开发者ID:Meituan-Dianping,项目名称:walle,代码行数:35,代码来源:V1SchemeSigner.java

示例2: getEncoded

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
public byte[] getEncoded()
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);
    SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPublicKeyStructure(getModulus(), getPublicExponent()).getDERObject());

    try
    {
        dOut.writeObject(info);
        dOut.close();
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding RSA public key");
    }

    return bOut.toByteArray();

}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:20,代码来源:JCERSAPublicKey.java

示例3: getEncoded

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
public byte[] getEncoded()
       throws CRLException
{
	ByteArrayOutputStream	bOut = new ByteArrayOutputStream();
	DEROutputStream			dOut = new DEROutputStream(bOut);

	try
	{
		dOut.writeObject(c);

		return bOut.toByteArray();
	}
	catch (IOException e)
	{
		throw new CRLException(e.toString());
	}
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:18,代码来源:X509CRLObject.java

示例4: getTBSCertList

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
public byte[] getTBSCertList()
	throws CRLException
{
	ByteArrayOutputStream	bOut = new ByteArrayOutputStream();
	DEROutputStream			dOut = new DEROutputStream(bOut);

	try
	{
		dOut.writeObject(c.getTBSCertList());

		return bOut.toByteArray();
	}
	catch (IOException e)
	{
		throw new CRLException(e.toString());
	}
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:18,代码来源:X509CRLObject.java

示例5: getSigAlgParams

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
public byte[] getSigAlgParams()
{
	ByteArrayOutputStream	bOut = new ByteArrayOutputStream();

	if ( c.getSignatureAlgorithm().getParameters() != null )
	{
		try
		{
			DEROutputStream	dOut = new DEROutputStream(bOut);

			dOut.writeObject(c.getSignatureAlgorithm().getParameters());
		}
		catch (Exception e)
		{
			throw new RuntimeException("exception getting sig parameters " + e);
		}

		return bOut.toByteArray();
	}

	return null;
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:23,代码来源:X509CRLObject.java

示例6: getEncoded

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
public byte[] getEncoded()
	throws CRLException
{
	ByteArrayOutputStream	bOut = new ByteArrayOutputStream();
	DEROutputStream			dOut = new DEROutputStream(bOut);

	try
	{
		dOut.writeObject(c);

		return bOut.toByteArray();
	}
	catch (IOException e)
	{
		throw new CRLException(e.toString());
	}
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:18,代码来源:X509CRLEntryObject.java

示例7: getEncoded

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
/**
 * return a DER encoded byte array representing this object
 */
public byte[] getEncoded()
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(this);
    }
    catch (IOException e)
    {
        throw new RuntimeException(e.toString());
    }

    return bOut.toByteArray();
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:20,代码来源:X509Principal.java

示例8: addExtension

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
/**
 * Add an extension with the given oid and the passed in value to be included
 * in the OCTET STRING associated with the extension.
 *
 * @param oid  OID for the extension.
 * @param critical  true if critical, false otherwise.
 * @param value the ASN.1 object to be included in the extension.
 */
public void addExtension(
    DERObjectIdentifier oid,
    boolean             critical,
    DEREncodable        value)
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(value);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("error encoding value: " + e);
    }

    this.addExtension(oid, critical, bOut.toByteArray());
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:28,代码来源:X509ExtensionsGenerator.java

示例9: generateSignatureBlock

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
private static byte[] generateSignatureBlock(SignerConfig signerConfig, byte[] signatureFileBytes) throws InvalidKeyException, CertificateEncodingException, SignatureException {
	JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
	X509Certificate signerCert = signerConfig.certificates.get(0);
	String jcaSignatureAlgorithm = getJcaSignatureAlgorithm(signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
	try {
		ContentSigner signer = new JcaContentSignerBuilder(jcaSignatureAlgorithm).build(signerConfig.privateKey);
		CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
		gen.addSignerInfoGenerator(new SignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build(), SignerInfoSignatureAlgorithmFinder.INSTANCE).setDirectSignature(true).build(signer,
				new JcaX509CertificateHolder(signerCert)));
		gen.addCertificates(certs);

		CMSSignedData sigData = gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
			DEROutputStream dos = new DEROutputStream(out);
			dos.writeObject(asn1.readObject());
		}
		return out.toByteArray();
	} catch (OperatorCreationException | CMSException | IOException e) {
		throw new SignatureException("Failed to generate signature", e);
	}
}
 
开发者ID:abutun,项目名称:apk-verifier,代码行数:24,代码来源:V1SchemeSigner.java

示例10: addExtension

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
/**
 * add a given extension field for the standard extensions tag (tag 0)
 */
public void addExtension(
    DERObjectIdentifier OID,
    boolean             critical,
    DEREncodable        value)
{
    if (extensions == null)
    {
        extensions = new Hashtable();
        extOrdering = new Vector();
    }

    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(value);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("error encoding value: " + e);
    }

    this.addExtension(OID, critical, bOut.toByteArray());
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:29,代码来源:X509V2CRLGenerator.java

示例11: derEncode

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
private byte[] derEncode(
    BigInteger  r,
    BigInteger  s)
    throws IOException
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);
    ASN1EncodableVector     v = new ASN1EncodableVector();

    v.add(new DERInteger(r));
    v.add(new DERInteger(s));

    dOut.writeObject(new DERSequence(v));

    return bOut.toByteArray();
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:17,代码来源:JDKDSASigner.java

示例12: testCommandMessageRoundTrip

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
@Test
public void testCommandMessageRoundTrip()
    throws Exception
{

    CommandMessage msg = new CommandMessage(CommandMessage.Type.ACTIVATE_BOARD, new ASN1Integer(1));

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DEROutputStream derOut = new DEROutputStream(bos);

    derOut.writeObject(msg.toASN1Primitive());

    ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
    ASN1InputStream din = new ASN1InputStream(bin);

    CommandMessage res = CommandMessage.getInstance(din.readObject());

    TestCase.assertEquals(msg.getPayload(), res.getPayload());
    TestCase.assertEquals(msg.getType(), res.getType());
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:21,代码来源:MessageTest.java

示例13: testPermuteAndMoveRoundTrip_1

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
@Test
public void testPermuteAndMoveRoundTrip_1()
    throws Exception
{

    PermuteAndMoveMessage msg = new PermuteAndMoveMessage(1, "Cat", 0, "Doc", "Fish", "Rabbit");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DEROutputStream derOut = new DEROutputStream(bos);

    derOut.writeObject(msg.toASN1Primitive());

    ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
    ASN1InputStream din = new ASN1InputStream(bin);

    PermuteAndMoveMessage res = PermuteAndMoveMessage.getInstance(din.readObject());

    TestCase.assertEquals(msg.getBoardName(), res.getBoardName());
    TestCase.assertEquals(msg.getDestinationNode(), res.getDestinationNode());
    TestCase.assertEquals(msg.getKeyID(), res.getKeyID());
    TestCase.assertEquals(msg.getTransformName(), res.getTransformName());

}
 
开发者ID:cwgit,项目名称:ximix,代码行数:24,代码来源:MessageTest.java

示例14: testPermuteAndMoveRoundTrip_2

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
@Test
public void testPermuteAndMoveRoundTrip_2()
    throws Exception
{

    PermuteAndMoveMessage msg = new PermuteAndMoveMessage(1, "Cat", 0, "Doc", null, "Rabbit");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DEROutputStream derOut = new DEROutputStream(bos);

    derOut.writeObject(msg.toASN1Primitive());

    ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
    ASN1InputStream din = new ASN1InputStream(bin);

    PermuteAndMoveMessage res = PermuteAndMoveMessage.getInstance(din.readObject());

    TestCase.assertEquals(msg.getBoardName(), res.getBoardName());
    TestCase.assertEquals(msg.getDestinationNode(), res.getDestinationNode());
    TestCase.assertEquals(msg.getKeyID(), res.getKeyID());
    TestCase.assertEquals(msg.getTransformName(), res.getTransformName());

}
 
开发者ID:cwgit,项目名称:ximix,代码行数:24,代码来源:MessageTest.java

示例15: testBoardErrorStatusMessage_1

import org.bouncycastle.asn1.DEROutputStream; //导入依赖的package包/类
@Test
 public void testBoardErrorStatusMessage_1()
     throws Exception
 {
     BoardErrorStatusMessage msg = new BoardErrorStatusMessage("foo", BoardErrorStatusMessage.Status.NOT_SHUFFLE_LOCKED);

     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     DEROutputStream derOut = new DEROutputStream(bos);

     derOut.writeObject(msg.toASN1Primitive());

     ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
     ASN1InputStream din = new ASN1InputStream(bin);

     BoardErrorStatusMessage res = BoardErrorStatusMessage.getInstance(ASN1TaggedObject.getInstance(din.readObject()).getObject());


     TestCase.assertEquals(msg.getBoardName(), res.getBoardName());
     TestCase.assertEquals(msg.getStatus(), res.getStatus());
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:21,代码来源:MessageTest.java


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