Is it possible to use crypto++ library to decode arbitrary ASN1 data (which has couple of sequences and integers) which I have in a byte array. ash.h contains methods which all take BufferedTransformation as input, but that class is interface for different ciphers and hashes, which really seems to be not related to my simple case at all. I also found ASN1Object in cryptlib.h but it's another interface and I haven't managed to find any implementing classes.
Have I thought it way too complex for myself or is it actually difficult to decode arbitrary ASN1 data?
I am actually using this in Swift/objective-c iOS application, so if anyone has a simple solution with whatever else tool, let me know.
EDIT: Adding an example structure of the data
SEQUENCE
SEQUENCE
INTEGER
INTEGER
SEQUENCE
INTEGER
INTEGER
There's always the parent sequence which contains 1 to n sequences which contain 2 integers (elgamal encryption pair (g^r, mh^r)) each.
For this, you would want something like:
Once you have the parameters (see below), you should call one of the
Initialize
functions with the parameters. Don't call the ones that take a PRNG because they create parameters and keys.See gfpcrypt.h for some of the relevant class definitions. Also see ElGamal - Crypto++ Wiki.
Here's an example that generates integer pairs and packages them in ASN.1 structures like you desire. It then reads them back in and stops when there's nothing left to consume (i.e., the inner Integer pairs are optional).
You would run it like
./asn1-test.exe
or./asn1-test.exe 3
or./asn1-test.exe 6
or./asn1-test.exe 128
. The size is only 48-bits so you don't waste time generating integers you don't need.And here's what a run and dump looks like:
Here are the includes to save you the trouble of looking them up: