Java 类org.bouncycastle.asn1.DEROutputStream 实例源码

项目:walle    文件:V1SchemeSigner.java   
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);
    }
}
项目:Direct-File-Downloader    文件:JCERSAPublicKey.java   
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();

}
项目:Direct-File-Downloader    文件:X509CRLObject.java   
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());
    }
}
项目:Direct-File-Downloader    文件:X509CRLObject.java   
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());
    }
}
项目:Direct-File-Downloader    文件:X509CRLObject.java   
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;
}
项目:Direct-File-Downloader    文件:X509CRLEntryObject.java   
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());
    }
}
项目:Direct-File-Downloader    文件:X509Principal.java   
/**
 * 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();
}
项目:Direct-File-Downloader    文件:X509ExtensionsGenerator.java   
/**
 * 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());
}
项目:apk-verifier    文件:V1SchemeSigner.java   
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);
    }
}
项目:AcademicTorrents-Downloader    文件:X509V2CRLGenerator.java   
/**
 * 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());
}
项目:AcademicTorrents-Downloader    文件:JCERSAPublicKey.java   
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();

}
项目:AcademicTorrents-Downloader    文件:X509CRLObject.java   
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());
    }
}
项目:AcademicTorrents-Downloader    文件:X509CRLObject.java   
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());
    }
}
项目:AcademicTorrents-Downloader    文件:X509CRLObject.java   
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;
}
项目:AcademicTorrents-Downloader    文件:JDKDSASigner.java   
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();
}
项目:AcademicTorrents-Downloader    文件:X509CRLEntryObject.java   
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());
    }
}
项目:AcademicTorrents-Downloader    文件:PKCS10CertificationRequest.java   
/**
 * 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();
}
项目:AcademicTorrents-Downloader    文件:X509Principal.java   
/**
 * 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();
}
项目:AcademicTorrents-Downloader    文件:X509ExtensionsGenerator.java   
/**
 * 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());
}
项目:ximix    文件:MessageTest.java   
@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());
}
项目:ximix    文件:MessageTest.java   
@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());

}
项目:ximix    文件:MessageTest.java   
@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());

}
项目:ximix    文件:MessageTest.java   
@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());
}
项目:ximix    文件:MessageTest.java   
@Test
public void testBigIntegerMessage_1()
    throws Exception
{
    BigIntegerMessage msg = new BigIntegerMessage(BigInteger.valueOf(Long.MAX_VALUE));

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

    derOut.writeObject(msg.toASN1Primitive());

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

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

    TestCase.assertEquals(msg.getValue(), res.getValue());
}
项目:ximix    文件:DefaultXimixNode.java   
/**
 * @param s
 * @throws Exception
 */
protected void respondExiting(Socket s)
    throws Exception
{

    OutputStream sOut = s.getOutputStream();

    DEROutputStream aOut = new DEROutputStream(sOut);
    // TODO: NodeInfo actually is the first object in the protocol
    aOut.writeObject(new MessageReply(MessageReply.Type.EXITING));
    aOut.flush();
    aOut.close();

    s.close();

}
项目:irma_future_id    文件:EncryptedPrivateKeyInfo.java   
private AlgorithmParameters getParameters()
    throws NoSuchAlgorithmException
{
    AlgorithmParameters     ap = AlgorithmParameters.getInstance(this.getAlgName());
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(infoObj.getEncryptionAlgorithm().getParameters());
        dOut.close();

        ap.init(bOut.toByteArray());
    }
    catch (IOException e)
    {
        throw new NoSuchAlgorithmException("unable to parse parameters");
    }

    return ap;
}
项目:irma_future_id    文件:CertUtil.java   
/**
 * Parse the given rfc822 addr-spec into DER encoded byte array
 * representation.
 * 
 * @param the
 *            rfc822 addr-spec in well known String format
 * 
 * @return the rfc822 addr-spec as byte array
 * 
 * @exception IOException
 *                if the String could not be parsed
 */
private static byte[] parseRfc822(String data) throws IOException
{
    int tmpInt = data.indexOf('@');
    if (tmpInt < 0 || tmpInt >= data.length() - 1)
    {
        throw new IOException("wrong format of rfc822Name:" + data);
    }
    // TODO more test for illegal charateers
    ASN1Object derData = new DERIA5String(data);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    DEROutputStream derOutStream = new DEROutputStream(outStream);
    derOutStream.writeObject(derData);
    derOutStream.close();
    return outStream.toByteArray();
}
项目:irma_future_id    文件:PolicyQualifierInfo.java   
/**
 * Creates an instance of <code>PolicyQualifierInfo</code> from the
 * encoded bytes. The encoded byte array is copied on construction.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Sequence ASN1Sequence},
 * {@link org.bouncycastle.asn1.ASN1ObjectIdentifier ASN1ObjectIdentifier} and
 * {@link org.bouncycastle.asn1.DEROutputStream DEROutputStream}
 * 
 * @param encoded
 *            a byte array containing the qualifier in DER encoding
 * 
 * @exception IOException
 *                thrown if the byte array does not represent a valid and
 *                parsable policy qualifier
 */
public PolicyQualifierInfo(byte[] encoded) throws IOException
{
    this.encoded = (byte[])encoded.clone();
    try
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(
                this.encoded);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Sequence obj = (ASN1Sequence)derInStream.readObject();
        id = ((ASN1ObjectIdentifier)obj.getObjectAt(0)).getId();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        DEROutputStream derOutStream = new DEROutputStream(outStream);

        derOutStream.writeObject(obj.getObjectAt(1));
        derOutStream.close();

        qualifier = outStream.toByteArray();
    }
    catch (Exception ex)
    {
        throw new IOException("parsing exception : " + ex.toString());
    }
}
项目:irma_future_id    文件:CertUtil.java   
/**
 * Parse the given rfc822 addr-spec into DER encoded byte array
 * representation.
 * 
 * @param the
 *            rfc822 addr-spec in well known String format
 * 
 * @return the rfc822 addr-spec as byte array
 * 
 * @exception IOException
 *                if the String could not be parsed
 */
private static byte[] parseRfc822(String data) throws IOException
{
    int tmpInt = data.indexOf('@');
    if (tmpInt < 0 || tmpInt >= data.length() - 1)
    {
        throw new IOException("wrong format of rfc822Name:" + data);
    }
    // TODO more test for illegal charateers
    ASN1Object derData = new DERIA5String(data);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    DEROutputStream derOutStream = new DEROutputStream(outStream);
    derOutStream.writeObject(derData);
    derOutStream.close();
    return outStream.toByteArray();
}
项目:irma_future_id    文件:PolicyQualifierInfo.java   
/**
 * Creates an instance of <code>PolicyQualifierInfo</code> from the
 * encoded bytes. The encoded byte array is copied on construction.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Sequence ASN1Sequence},
 * {@link org.bouncycastle.asn1.ASN1ObjectIdentifier ASN1ObjectIdentifier} and
 * {@link org.bouncycastle.asn1.DEROutputStream DEROutputStream}
 * 
 * @param encoded
 *            a byte array containing the qualifier in DER encoding
 * 
 * @exception IOException
 *                thrown if the byte array does not represent a valid and
 *                parsable policy qualifier
 */
public PolicyQualifierInfo(byte[] encoded) throws IOException
{
    this.encoded = (byte[])encoded.clone();
    try
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(
                this.encoded);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Sequence obj = (ASN1Sequence)derInStream.readObject();
        id = ((ASN1ObjectIdentifier)obj.getObjectAt(0)).getId();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        DEROutputStream derOutStream = new DEROutputStream(outStream);

        derOutStream.writeObject(obj.getObjectAt(1));
        derOutStream.close();

        qualifier = outStream.toByteArray();
    }
    catch (Exception ex)
    {
        throw new IOException("parsing exception : " + ex.toString());
    }
}
项目:irma_future_id    文件:JDKAlgorithmParameters.java   
protected byte[] engineGetEncoded() 
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(params);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Oooops! " + e.toString());
    }

    return bOut.toByteArray();
}
项目:irma_future_id    文件:JDKAlgorithmParameters.java   
/**
 * in the abscence of a standard way of doing it this will do for
 * now...
 */
protected byte[] engineGetEncoded() 
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        ASN1EncodableVector    v = new ASN1EncodableVector();

        v.add(new DEROctetString(currentSpec.getDerivationV()));
        v.add(new DEROctetString(currentSpec.getEncodingV()));
        v.add(new DERInteger(currentSpec.getMacKeySize()));

        dOut.writeObject(new DERSequence(v));
        dOut.close();
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding IESParameters");
    }

    return bOut.toByteArray();
}
项目:bc-java    文件:EncryptedPrivateKeyInfo.java   
private AlgorithmParameters getParameters()
    throws NoSuchAlgorithmException
{
    AlgorithmParameters     ap = AlgorithmParameters.getInstance(this.getAlgName());
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(infoObj.getEncryptionAlgorithm().getParameters());
        dOut.close();

        ap.init(bOut.toByteArray());
    }
    catch (IOException e)
    {
        throw new NoSuchAlgorithmException("unable to parse parameters");
    }

    return ap;
}
项目:bc-java    文件:CertUtil.java   
/**
 * Parse the given rfc822 addr-spec into DER encoded byte array
 * representation.
 * 
 * @param the
 *            rfc822 addr-spec in well known String format
 * 
 * @return the rfc822 addr-spec as byte array
 * 
 * @exception IOException
 *                if the String could not be parsed
 */
private static byte[] parseRfc822(String data) throws IOException
{
    int tmpInt = data.indexOf('@');
    if (tmpInt < 0 || tmpInt >= data.length() - 1)
    {
        throw new IOException("wrong format of rfc822Name:" + data);
    }
    // TODO more test for illegal charateers
    ASN1Object derData = new DERIA5String(data);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    DEROutputStream derOutStream = new DEROutputStream(outStream);
    derOutStream.writeObject(derData);
    derOutStream.close();
    return outStream.toByteArray();
}
项目:bc-java    文件:PolicyQualifierInfo.java   
/**
 * Creates an instance of <code>PolicyQualifierInfo</code> from the
 * encoded bytes. The encoded byte array is copied on construction.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Sequence ASN1Sequence},
 * {@link org.bouncycastle.asn1.ASN1ObjectIdentifier ASN1ObjectIdentifier} and
 * {@link org.bouncycastle.asn1.DEROutputStream DEROutputStream}
 * 
 * @param encoded
 *            a byte array containing the qualifier in DER encoding
 * 
 * @exception IOException
 *                thrown if the byte array does not represent a valid and
 *                parsable policy qualifier
 */
public PolicyQualifierInfo(byte[] encoded) throws IOException
{
    this.encoded = (byte[])encoded.clone();
    try
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(
                this.encoded);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Sequence obj = (ASN1Sequence)derInStream.readObject();
        id = ((ASN1ObjectIdentifier)obj.getObjectAt(0)).getId();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        DEROutputStream derOutStream = new DEROutputStream(outStream);

        derOutStream.writeObject(obj.getObjectAt(1));
        derOutStream.close();

        qualifier = outStream.toByteArray();
    }
    catch (Exception ex)
    {
        throw new IOException("parsing exception : " + ex.toString());
    }
}
项目:bc-java    文件:CertUtil.java   
/**
 * Parse the given rfc822 addr-spec into DER encoded byte array
 * representation.
 * 
 * @param the
 *            rfc822 addr-spec in well known String format
 * 
 * @return the rfc822 addr-spec as byte array
 * 
 * @exception IOException
 *                if the String could not be parsed
 */
private static byte[] parseRfc822(String data) throws IOException
{
    int tmpInt = data.indexOf('@');
    if (tmpInt < 0 || tmpInt >= data.length() - 1)
    {
        throw new IOException("wrong format of rfc822Name:" + data);
    }
    // TODO more test for illegal charateers
    ASN1Object derData = new DERIA5String(data);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    DEROutputStream derOutStream = new DEROutputStream(outStream);
    derOutStream.writeObject(derData);
    derOutStream.close();
    return outStream.toByteArray();
}
项目:bc-java    文件:PolicyQualifierInfo.java   
/**
 * Creates an instance of <code>PolicyQualifierInfo</code> from the
 * encoded bytes. The encoded byte array is copied on construction.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Sequence ASN1Sequence},
 * {@link org.bouncycastle.asn1.ASN1ObjectIdentifier ASN1ObjectIdentifier} and
 * {@link org.bouncycastle.asn1.DEROutputStream DEROutputStream}
 * 
 * @param encoded
 *            a byte array containing the qualifier in DER encoding
 * 
 * @exception IOException
 *                thrown if the byte array does not represent a valid and
 *                parsable policy qualifier
 */
public PolicyQualifierInfo(byte[] encoded) throws IOException
{
    this.encoded = (byte[])encoded.clone();
    try
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(
                this.encoded);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Sequence obj = (ASN1Sequence)derInStream.readObject();
        id = ((ASN1ObjectIdentifier)obj.getObjectAt(0)).getId();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        DEROutputStream derOutStream = new DEROutputStream(outStream);

        derOutStream.writeObject(obj.getObjectAt(1));
        derOutStream.close();

        qualifier = outStream.toByteArray();
    }
    catch (Exception ex)
    {
        throw new IOException("parsing exception : " + ex.toString());
    }
}
项目:bc-java    文件:JDKAlgorithmParameters.java   
protected byte[] engineGetEncoded() 
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        dOut.writeObject(params);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Oooops! " + e.toString());
    }

    return bOut.toByteArray();
}
项目:bc-java    文件:JDKAlgorithmParameters.java   
/**
 * in the abscence of a standard way of doing it this will do for
 * now...
 */
protected byte[] engineGetEncoded() 
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    DEROutputStream         dOut = new DEROutputStream(bOut);

    try
    {
        ASN1EncodableVector    v = new ASN1EncodableVector();

        v.add(new DEROctetString(currentSpec.getDerivationV()));
        v.add(new DEROctetString(currentSpec.getEncodingV()));
        v.add(new DERInteger(currentSpec.getMacKeySize()));

        dOut.writeObject(new DERSequence(v));
        dOut.close();
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding IESParameters");
    }

    return bOut.toByteArray();
}
项目:ipack    文件:CertUtils.java   
private static byte[] generateSig(ContentSigner signer, ASN1Encodable tbsObj)
    throws IOException
{
    OutputStream sOut = signer.getOutputStream();
    DEROutputStream dOut = new DEROutputStream(sOut);

    dOut.writeObject(tbsObj);

    sOut.close();

    return signer.getSignature();
}