Skip to content

A library to parse and generate Visible Digital Seals (VDS)

License

Notifications You must be signed in to change notification settings

tsenger/vdstools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VdsTools - lib to decode/verify and encode/sign Visible Digital Seals

License Maven Central Version GitHub Actions Workflow Status

A library to decode/verify and encode/sign Visible Digital Seals (VDS) as specified in

VDS can be created with the help of this library or, if you want to try it out quickly, via the web Sealgen tool. There is also the Sealva Android app which scans, verifies and displays all VDS profiles defined in the above specifications.

Get it on Google Play

Parse and verify a VDS

Here is a quick overview how to use the VDS parser and verifier. When you have the decoded raw string or raw bytes from your favorite datamatrix decoder, just put them to the VDS Tools Dataparser like this:

import de.tsenger.vdstools.DataParser;
import de.tsenger.vdstools.Verifier;
import de.tsenger.vdstools.seals.DigitalSeal;
import de.tsenger.vdstools.seals.VdsType;
import de.tsenger.vdstools.seals.Feature;

	...
	DigitalSeal digitalSeal = DataParser.parseVdsSeal(rawBytes);
	VdsType vdsType = digitalSeal.getVdsType()
	
	// Depending on the returned VDS type you can access the seals content
	String mrz = (String) seal.getFeature(Feature.MRZ);
	String azr = (String) seal.getFeature(Feature.AZR);
   
	// Get the VDS signer certificate reference
	String signerCertRef = digitalSeal.getSignerCertRef();
   
	// Provide for the matching X509 signer certificate
	// and use this to verify the VDS signature   
	Verifier verifier = new Verifier(digitalSeal, x509SignerCert);
	Verifier.Result result = verifier.verify();
	
	

Also have a look at DataParserTest.java and VerifierTest.java for some more examples.

Build a new VDS

Since version 0.3.0 you can also generate VDS with this library. Here is an example on how to use the DateEncoder and Signer classes:

KeyStore keystore = ...
...
String mrz = "ATD<<RESIDORCE<<ROLAND<<<<<<<<<<<<<<6525845096USA7008038M2201018<<<<<<06";
String passportNumber = "UFO001979";
VdsMessage vdsMessage = new VdsMessage(VdsType.RESIDENCE_PERMIT);
vdsMessage.addDocumentFeature(Feature.MRZ, mrz);
vdsMessage.addDocumentFeature(Feature.PASSPORT_NUMBER, passportNumber);

// Here we use a keystore to get the certificate (for the header information)
// and the private key for signing the seals data
X509Certificate cert = (X509Certificate) keystore.getCertificate(keyAlias);
ECPrivateKey ecKey = (ECPrivateKey) keystore.getKey(certAlias, keyStorePassword.toCharArray());

// initialize the Signer
Signer signer = new Signer(ecKey); 
	
// Build the the VDS
// Here the header information will be read from the certificate content and the message.
DigitalSeal digitalSeal = DataEncoder.buildDigitalSeal(vdsMessage, cert, signer);

// The encoded bytes can now be used to build a datamatrix (or other) code - which is not part of this library
byte[] encodedBytes = digitalSeal.getEncodedBytes();

There are many other ways to define the content of the VDS. In the example above, a lot of data such as the signature or issuing date is generated automatically. However, it is also possible to set your own values. There are various buildDigitalSeal methods in the DataEncoder for this purpose. The VdsHeader and VdsMessage classes offer the option of setting the content in a finely granular manner.

Alternatively, it is also possible to generate many values automatically with as little input as possible or to use default values.

Also have a look at DataEncoderTest.java for some examples how to use the different options. In DataMatrixTest.java you will find an example on how to generated a datamatrix image file from the encoded bytes of the DataEncoder.

Documentation

JavaDoc can be found here:

https://javadoc.jitpack.io/com/github/tsenger/vdstools/latest/javadoc/index.html

How to include

The vdstools library is available on the Maven Central Repository and can be easly integrated in your projects.

Gradle

To include this library to your Gradle build add this dependency:

dependencies {
    implementation 'de.tsenger:vdstools:0.3.2'
}

Maven

To include this library to your Maven build add this dependency:

<dependency>
    <groupId>de.tsenger</groupId>
    <artifactId>vdstools</artifactId>
    <version>0.3.2</version>
</dependency>