- ECDSA
- EDDSA
- RSA
Algorithm | Curve / Length |
---|---|
ECDSA | secp256r1 (prime256v1 in OpenSSL) |
EDDSA | Ed25519 |
RSA | 3072 bits |
Examples
- OpenSSL CLI
- Node.js Crypto
- Web Crypto
- AWS CLI
Signature Format
An ECDSA (which includes EDDSA) signature consists of two values; ar
and a s
. Different crypto libraries use different formats for encoding these two values. The two most popular formats are ASN.1 / DER format
and raw format
.
Dfns APIs expects ECDSA/EDDSA signatures to use the ASN.1 / DER
format.
Raw Signatures
Withraw
, the r
and s
values are directly concatenated together to form the signature. Each value must be exactly 32 bytes long, with 0s added to the beginning of the r/s
if it is less then 32 bytes.
ASN.1 / DER
WithASN.1 / DER
, the values are encoded using a deterministic format. The first byte is a magic value (0x30
) that is used to identify the encoding. The second byte is the remaining length of the signature. The remaining bytes are the encoded r
and s
values. Each one is formated with its first byte being a magic value / separator (0x02
). The second byte being the length of the value. And the remaining bytes being the value as a minimal-sized signed big-endian hex number
. This means the number has all leading zeros removed, then the first byte must be a positive number (0x00
-0x7F
). If the minimized number starts with a negative value (0x80
-0xFF
) a zero is added to the beginning of the number. This means the final length of the value could be anywhere between 1 bytes and 33 bytes.
Converting from Raw to ASN.1
If your encryption library usesraw format
you can convert it to ASN.1 DER
using the following code:
Base64 and Base64Url Encoding
Base64 is a popular way of encoding large values into a string that contains only printable characters. Base64Url is an extension of Base64 encoding, but replaces characters that are not safe in URLs with different characters. It also minimizes the string, removing the extra padding characters. The Dfns auth system leverages Base64Url encoding in many different places. In nodeJS,Buffer
has built-in support for Base64Url as an encoding type.
Buffer
is not available, or an older Buffer
implementation is used, this code can be used to convert a value to a Base64Url encoded string: