本文整理汇总了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);
}
}
示例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();
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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());
}
}
示例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();
}
示例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());
}
示例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);
}
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}