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

项目:keystore-explorer    文件:X509Ext.java   
private String getEntrustVersionInformationStringValue(byte[] value) throws IOException {
    // @formatter:off

    /*
     * EntrustVersInfoSyntax ::= OCTET STRING
     *
     * entrustVersInfo EXTENSION ::= { SYNTAX EntrustVersInfoSyntax,
     * IDENTIFIED BY {id-entrust 0} }
     *
     * EntrustVersInfoSyntax ::= ASN1Sequence { entrustVers GeneralString,
     * entrustInfoFlags EntrustInfoFlags }
     *
     * EntrustInfoFlags ::= BIT STRING { keyUpdateAllowed newExtensions (1),
     * pKIXCertificate (2) }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    ASN1Sequence entrustVersInfo = (ASN1Sequence) ASN1Primitive.fromByteArray(value);

    DERGeneralString entrustVers = (DERGeneralString) entrustVersInfo.getObjectAt(0);
    DERBitString entrustInfoFlags = (DERBitString) entrustVersInfo.getObjectAt(1);

    sb.append(MessageFormat.format(res.getString("EntrustVersion"), entrustVers.getString()));
    sb.append(NEWLINE);
    sb.append(MessageFormat.format(res.getString("EntrustInformationFlags"), entrustInfoFlags.getString()));
    sb.append(NEWLINE);

    return sb.toString();
}
项目:keystore-explorer    文件:Asn1Dump.java   
private String dumpString(ASN1String asn1String) {
    StringBuilder sb = new StringBuilder();

    sb.append(indentSequence.toString(indentLevel));

    if (asn1String instanceof DERBMPString) {
        sb.append("BMP STRING=");
    } else if (asn1String instanceof DERGeneralString) {
        sb.append("GENERAL STRING=");
    } else if (asn1String instanceof DERIA5String) {
        sb.append("IA5 STRING=");
    } else if (asn1String instanceof DERNumericString) {
        sb.append("NUMERIC STRING=");
    } else if (asn1String instanceof DERPrintableString) {
        sb.append("PRINTABLE STRING=");
    } else if (asn1String instanceof DERT61String) {
        sb.append("TELETEX STRING=");
    } else if (asn1String instanceof DERUniversalString) {
        sb.append("UNIVERSAL STRING=");
    } else if (asn1String instanceof DERUTF8String) {
        sb.append("UTF8 STRING=");
    } else if (asn1String instanceof DERVisibleString) {
        sb.append("VISIBLE STRING=");
    } else {
        sb.append("UNKNOWN STRING=");
    }

    sb.append("'");
    sb.append(asn1String.getString());
    sb.append("'");
    sb.append(NEWLINE);

    return sb.toString();
}
项目:JaasLounge    文件:DerOutputStream.java   
DerOutputStream putGeneralString(String s) throws IOException {
    aos.writeObject(new DERGeneralString(s));
    return this;
}
项目:JaasLounge    文件:DerInputStream.java   
String getGeneralString() throws IOException {
    DERGeneralString obj = DERGeneralString.getInstance(is.readObject());
    return obj.getString();
}
项目:irma_future_id    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}
项目:bc-java    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}
项目:vbrowser    文件:VOMSAttributeCertificate.java   
public ArrayList<String> getVOMSFQANs() throws Exception
{
    ArrayList<String> theseFQANs = new ArrayList<String>() ;
    try
    {
        // could have more than one AC in here...
        for( Enumeration a = this.attributes.getObjects() ; a.hasMoreElements() ; )
        {

            ASN1Sequence sequence = (ASN1Sequence) a.nextElement() ;
            // sequence contains the OID [voms 4] (as a DERObjectIdentifier) at address 0 , and an SET at address 1

            ASN1Set set = (ASN1Set) sequence.getObjectAt( 1 ) ;
            // set contains only a SEQUENCE at address 0

            ASN1Sequence sequence2 = (ASN1Sequence) set.getObjectAt( 0 ) ;
            // sequence2 contains a TAGGED OBJECT ad address 0 and another SEQUENCE at address 1

            ASN1TaggedObject taggedObject = (ASN1TaggedObject) sequence2.getObjectAt( 0 ) ;
            // dig down the tagged object... (undocumented?) - TagNumber value is 0

            ASN1TaggedObject taggedObject2 = (ASN1TaggedObject) taggedObject.getObject() ;
            // this tagged object has TagNumber value of 6 (?)
            ASN1OctetString originOctetString = (ASN1OctetString) taggedObject2.getObject() ;
            String origin = ( new DERGeneralString( originOctetString.getOctets() ) ).getString() ;

            ASN1Sequence fqanSequence = (ASN1Sequence) sequence2.getObjectAt( 1 ) ;
            // this is the actual sequence of FQANs

            for( int fqan = 0 ; fqan < fqanSequence.size() ; fqan ++ )
            {
                ASN1OctetString fqanOctetString = (ASN1OctetString) fqanSequence.getObjectAt( fqan ) ;
                String FQAN_Value = ( new DERGeneralString( fqanOctetString.getOctets() ) ).getString() ;
                theseFQANs.add( FQAN_Value ) ;
            }
        }
    }
    catch( Exception e )
    {
        throw e ;
    }

    return theseFQANs ;
}
项目:vbrowser    文件:VOMSAttributeCertificate.java   
public void setVOMSFQANs( String[] fqans ) throws Exception
{
    try
    {
        //--------------------------------------------------------------------------
        // put the FQANs into the SEQUENCE

        DEREncodableVector fqanVector = new ASN1EncodableVector() ;

        for( int f = 0 ; f < fqans.length ; f ++ )
        {
            DERGeneralString fqan = new DERGeneralString( fqans[f] ) ;
            ASN1OctetString fqanOctetString = ASN1OctetString.getInstance( new DEROctetString( fqan.getOctets() ) ) ;
            fqanVector.add( fqanOctetString ) ;
        }

        ASN1Sequence fqanSequence = ASN1Sequence.getInstance( new DERSequence( fqanVector ) ) ;

        //--------------------------------------------------------------------------
        // put something into the undocumented TaggedObject

        DERGeneralString origin = new DERGeneralString( "gridportal://newvoms:15000" ) ;

        ASN1OctetString originOctetString = ASN1OctetString.getInstance( new DEROctetString( origin.getOctets() ) ) ;

        /*
     ASN1TaggedObject taggedObject2 = ASN1TaggedObject.getInstance( new DERTaggedObject( 6 , originOctetString ) , true ) ;

     ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance( new DERTaggedObject( 0 , taggedObject2 ) , true ) ;

     DEROctetString originOctetString = new DEROctetString( origin.getOctets() ) ;
         */

        DERTaggedObject taggedObject2 = new DERTaggedObject( 6 , originOctetString ) ;

        DERTaggedObject taggedObject = new DERTaggedObject( 0 , taggedObject2 ) ;

        //--------------------------------------------------------------------------
        // put the taggedObject and then the fqanSequence into sequence2

        DEREncodableVector sequence2Vector = new ASN1EncodableVector() ;
        sequence2Vector.add( taggedObject ) ;
        sequence2Vector.add( fqanSequence ) ;
        ASN1Sequence sequence2 = ASN1Sequence.getInstance( new DERSequence( sequence2Vector ) ) ;

        //--------------------------------------------------------------------------
        // the SET has one member - sequence2

        ASN1Set set = ASN1Set.getInstance( new DERSet( sequence2 ) ) ;

        //--------------------------------------------------------------------------
        // SEQUENCE sequence has an OID and the set

        DERObjectIdentifier voms4oid = new DERObjectIdentifier( "1.3.6.1.4.1.8005.100.100.4" ) ;

        DEREncodableVector sequenceVector = new ASN1EncodableVector() ;
        sequenceVector.add( voms4oid ) ;
        sequenceVector.add( set ) ;
        ASN1Sequence sequence = ASN1Sequence.getInstance( new DERSequence( sequenceVector ) ) ;

        //--------------------------------------------------------------------------

        this.attributes = ASN1Sequence.getInstance( new DERSequence( sequence ) ) ;

    }
    catch( Exception e )
    {
        throw e ;
    }

}