ASN.1 binary format into
raw format chunks tagged with class types.
ASN1.encode converts structured objects into
ASN.1 binary format.
ASN1.item creates an item - basic object in
structures that can be encoded using
ASN1.type extracts the class type from an
1 2 3 4
object to decode/encode/query
class type of the item (integer value)
This is a suite of low-level tools to deal with ASN.1 (Abstract Syntax
Notation One) binary formats DER, BER and CER. The tools were written
specifically to handle the various DER-encoded key structures so it
provides only a subset of the ASN.1 specification. They are used
internally by the
ASN1.decode decodes the binary representation (as raw vector)
into individual items. Sequences are convered into lists, all other
objects are retained in their binary form and tagged with the integer
class type - which can be obtained using
ASN1.encode expects item (or a list of items) either created
ASN1.item and converts them into
DER binary format.
The result of
ASN1.encode(ASN1.decode(x)) will be
x was in
ASN1.decode returns either one item or a list.
ASN1.encode returns a raw vector in DER format.
ASN1.type returns an integer class type
ASN1.item returns an ASN.1 item object
ASN1.encode uses a fixed buffer for encoding which currently
limits the total size of the resulting structure to 1MB.
Only definite length forms are supported. The validity of individual items is not checked.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# generate a small key key <- PKI.genRSAkey(bits = 512L) # extract private and public parts in DER format prv <- PKI.save.key(key, format="DER") pub <- PKI.save.key(key, private=FALSE, format="DER") # parse the public key x <- ASN1.decode(pub) x # the second element is the actual key # as a bit string that's itself in DER # two integers - modulus and exponent # Note that this is in fact the pure PKCS#1 key format ASN1.decode(x[]) # encoding it back should yield the same representation since it is DER stopifnot(identical(ASN1.encode(x), as.raw(pub)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.