Skip to content

HowTo encode the dynamic frame level 1

CGantert345 edited this page Jan 4, 2024 · 9 revisions

1. Preparing the content of the ticket

Prepare the ticket data as FCB Flexible Content Barcode

FCB

        IUicRailTicket ticket = new SimpleUicRailTicket();
    	// add your content to the FBC ticket description

2. Create an Encoder and add the ticket data and the version of the frame and the version of the FCB ticket data

        Encoder encoder = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_DOSIPAS, <frame version>, <FCB version>);

3. Add the level 1 data

	encoder.setLevel1Algs(<level 1 signature algorithm OID>, <level 1 key pair algorithm OID>);
	encoder.setLevel2Algs(<level 1 signature algorithm OID>, <level 1 key pair algorithm OID>,keyPairLevel2.getPublic());
        encoder.setLevel2Algs(<level 1 signature algorithm OID>, <level 1 key pair algorithm OID>,keyPairLevel2.getPublic(), <public key encoding>);

The level 2 public key will by default be encoded according to X.509 specification. For eliptic curve public keys it is possible to specify a different public key encoding:

  • Encoding according to X.509 specificatuion (Default): ECPublicKeyEncoder.ENCODING_X509 = "X509"
  • Encoding according to X9.62 uncompressed: ECPublicKeyEncoder.ENCODING_X962_UNCOMPESSED = "X962_UNCOMPRESSED"
  • Encoding according to X9.62 compressed: ECPublicKeyEncoder.ENCODING_X962_COMPESSED = "X962_COMPRESSED"
	encoder.getDynamicFrame().getLevel2Data().getLevel1Data().setEndOfBarcodeValidity(<end of bar code validity>);
	encoder.getDynamicFrame().getLevel2Data().getLevel1Data().setValidityDuration(<validity duration for level 2>);

4. Sign the data

The data can be signed. The Provider of the signature algortm can be provided to use a dedicated provider for the signature. If no provider is indicated the first provider that can handle the signature algorithm is used. There needs to be a provider registered which might be able to handle the signature.

       encoder.signLevel1(<SecurityProvider RICS code>, keyPair.getPrivate(), <algorithm OID>, <keyId>, <provider>);
       deprecated
       encoder.signLevel1(<SecurityProvider RICS code>, keyPair.getPrivate(), <algorithm OID>, <keyId>);

5. Encode the data

complete dynamic frame including level 1 content and signature

       byte[] encoded = encoder.encode();

level 1 data only

        byte[] encodedLevel1Data = encoder.getEncodedLevel1Data();
        byte[] signatureLevel1Data = encoder.getDynamicFrame().getLevel2Data().getLevel1Signature();