Hi All,
Could you please help me, im trying to create a ASN1Sequence from a DERObject. The following is the code that i am using and the error that i am getting.

ASN1InputStream ais = new ASN1InputStream(abyte0);
DERObject DEROctetString = ais.readObject();
ASN1Sequence asn1Sequence = (ASN1Sequence)DEROctetString;

Exception in thread "main" java.lang.ClassCastException: org.me.Mobile.DEROctetString cannot be cast to org.me.Mobile.ASN1Sequence

As far as im aware, the libraries i am using are right and it should work. Anyone have any ideas what i could be doing wrong?

Thanks in advance

I don't know these classes but from the code and the error I understand that when you are trying to do this:

ASN1Sequence asn1Sequence = (ASN1Sequence)DEROctetString;

The DEROctetString instance, is NOT an ASN1Sequence object, so it cannot be turned into one, using casting.
It is like saying something like this:

Integer integ = new Integer(10);
Date d = (Date)integ;

Thanks for replying.
I am using the JDKKeyFactory class from Bouncy castle library, and the following code is in the createPublicKeyFromDERStream function.

(ASN1Sequence)(new ASN1InputStream(abyte0)).readObject())

When i use this code i still get the same error.

could be the same reason Addict already mentioned.. the fact that the names look alike, don't always indicate they are linked to each other, or can be casted to one another

Hi All,
Could you please help me, im trying to create a ASN1Sequence from a DERObject. The following is the code that i am using and the error that i am getting.

ASN1InputStream ais = new ASN1InputStream(abyte0);
DERObject DEROctetString = ais.readObject();
ASN1Sequence asn1Sequence = (ASN1Sequence)DEROctetString;

Exception in thread "main" java.lang.ClassCastException: org.me.Mobile.DEROctetString cannot be cast to org.me.Mobile.ASN1Sequence

As far as im aware, the libraries i am using are right and it should work. Anyone have any ideas what i could be doing wrong?

Thanks in advance

Hi, Littlen. I have same problem with load public RSA key on MIDlet.

I get Exception " ClassCastException " on line ASN1Sequence ASNseq = (ASN1Sequence)DERobj Can you tell me please, how did you solve this problem?

This article has been dead for over six months. Start a new discussion instead.