Unable to Make Encrypted Barcode

I’d like to encrypt the data in my DataMatrix barcode but am unable to make the round trip. On the encoding side I have:

Dim s As String = DefineEncoding(TextToEncode,encodings.UTF8)
s = BlowfishMBS.Encrypt("kMyKey", s) // s is a byte sequence
s = EncodeBase64(s) // s is a "string"

Dim b As new BarcodeGeneratorMBS
b.Symbology = b.BarcodeDatamatrix
b.encode s

and on the decode side after scanning into a TextArea:

Dim s As String = DecodeBase64(TextArea1.Text)
s = BlowfishMBS.Decrypt("kMyKey", s)
s = DefineEncoding(s,encodings.UTF8)
OutputText = s

It works if I remove the barcoding and scanning parts, but after printing and scanning, the output is unprintable binary string data.

The scanner is a Zebra DS2208 emulating a keyboard.

I’d think that the Base64-encoded strings wouldn’t confuse the scanner or the OS keyboard interface or TextArea or BarcodeMBS, but maybe that’s an unfounded assumption.

Do the encoding to Base64 w/o EOL. Second parameter must be „false“.

The second parameter is an integer, with 0 indicating no line wrap, but that’s great to know, thanks. I think also I had my blowfish key wrong :slight_smile:

What is EOL? EndOfLine?
Is the second parameter in
s = DefineEncoding(s,encodings.UTF8) the encodings.UTF8 part. Are you saying it must be
s = DefineEncoding(s,false)

I’m asking how the posted code would look if corrected.

The documentation explains: EncodeBase64 — Xojo documentation

The talk/change here is about this line:

s = EncodeBase64(s) // s is a "string"

not about DefineEncoding, so that line changed to

s = EncodeBase64(s,0) // s is a "string"

s = EncodeBase64(s,0)

Sorry, of course I meant “0” not “false” to avoid the line ending. I think the barcode scanner cuts after an end-of-line and so you receive incomplete string.

No, the scanner won’t do that. It will send you all the characters it scans - most barcode scanners masquerade as keyboards to the computer. The more likely explanation is that there Return is kicking the cursor out of the text field, or being translated into a different character when it is read via Textfield.Value.

1 Like