All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.oer.OEREncoder Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls. This jar contains APIs for JDK 1.5 and up.

The newest version!
package org.bouncycastle.oer;

import java.io.ByteArrayOutputStream;

import org.bouncycastle.asn1.ASN1Encodable;

public class OEREncoder
{
    public static byte[] toByteArray(ASN1Encodable encodable, OERDefinition.Element oerElement)
    {
        try
        {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            new OEROutputStream(bos).write(encodable, oerElement);
            bos.flush();
            bos.close();
            return bos.toByteArray();
        }
        catch (Exception ex)
        {
            throw new IllegalStateException(ex.getMessage(), ex);
        }
    }

//    public static byte[] toByteArrayLogging(ASN1Encodable encodable, OERDefinition.Element oerElement)
//    {
//        try
//        {
//            ByteArrayOutputStream bos = new ByteArrayOutputStream();
//            new OEROutputStream(new FilterOutputStream(bos)
//            {
//                @Override
//                public void write(int b)
//                    throws IOException
//                {
//                    System.out.print(Hex.toHexString(new byte[]{(byte)(b & 0xFF)}));
//                    super.write(b);
//                }
//
//                @Override
//                public void write(byte[] b)
//                    throws IOException
//                {
//                    System.out.print(Hex.toHexString(b));
//                    super.write(b);
//                }
//
//                @Override
//                public void write(byte[] b, int off, int len)
//                    throws IOException
//                {
//                    Hex.toHexString(b, 0, len);
//                    super.write(b, off, len);
//                }
//            })
//            {
//                {
//                    debugOutput = new PrintWriter(System.out);
//                }
//            }.write(encodable, oerElement);
//            bos.flush();
//            bos.close();
//            return bos.toByteArray();
//        }
//        catch (Exception ex)
//        {
//            throw new IllegalStateException(ex.getMessage(), ex);
//        }
//    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy