Get readable output from RFID scanner for encrypted PDF417 barcode - barcode

I am testing a CipherLab handheld RFID reader to scan a driver license which has an encrypted PDF417 barcode with binary data.
When I scan the barcode, I get the below string values, which obviously means nothing. Is there a way to set the scanner to not return the barcode text "as is", but rather return the barcode as a base64 string or hex string.
Return string from barcode scan:
› E��¥—IÉ?K ×[´
=î®—æ~$Œ§òè>–Ǻ9?vƒÛîÎH†dò{EÑÆÃ:ô&œ ÓÀ
ø.ÖÊ\ñ…Ç#ÇÅ|'Å%f ö€Ïö€dð E¢öJAN¨µL¤Shwšr"ÜAœ#-¸;—L>ûlH;'ômƒJ²ê
ïB»Î‡#{jmÛXaùÛwÛø‰¸žZ»t±~ -K¦F€©òW-Ͷ˜\8q®'0eyÀV#"~AÓ×ÕP„]žsአT!ÿ½I±$¿wf¤Nä¢ÆS¯Ë,Åï]¯(p&°ë8éõ™ª-°· .$Ô¹ÃbÞ H/¥å0ž·F}ñ pÎ( üïê5Þ�åPdâb"˜Ñyc–á!D ;ÊX¦Ý!àï‡og ßÓø-D¥ª®&ÜÖÃ=܇‚Ô•¸6?ïþi«^^†ÃzÛÏMä!Ý®. :ô#ôÃ[Üv$YÔÄnÜ'¤¯ƒ"² kÖ‰ 0c‚&¼Gð7èé]·Í"ßáúÿ?ÀÓ™ÿÎÔn°åy¸(ÜÓŸ¹+Ÿø½1•Üt½Š¥é�f#5ëì¦f¶üñýÒ>ˆ¯JíóRqMÿ\ž¹|i/T£04¸¬~É¡aµˆßg wÙÌÿêú3fÒÇßÀሽÅÕ°;üð¾AÖP²3ÿ—‡V€§R€o;& »"¼ÔÃùÀ¤9À�wZß!<›ŠõU?!o+"¡©ùcœÒÄ Ö*ªjšé©Zkkæ¸u!{íxûñ{ñanõ ®|Á'LãBµ!í«xE:ÖsãÉ7„½øND'ƒôû—$âåÂ5öˆóòŠÐ0ýêYg#ù烃PíÂ\îpm¸‹')¨ƒœƒ4Ó+Šš$bqÖ¿xÜL
The barcode I am referring to:

Related

PDF does not use utf-8 string encoding like Go

I am working with libray (https://github.com/unidoc/unipdf) for Go to process PDF files. By using 'SetReason' method I try to set reason of signing of my pdf file.
func (_aggg *PdfSignature )SetReason (reason string ){_aggg .Reason =_gb .MakeString (reason )};
This leads to cyrillic text become unclear symbols (as shown in the picture).
unclear cyricclic symbols
original text is: "русский > Request Id = 12, Task Id = 145"
And it is all ok with cyrillic symbols in main content of PDF file. The problem is in 'Signs'('Подписи') part (as shown in the picture).
In the library there is a mention: (see 'NOTE')
// MakeString creates an PdfObjectString from a string.
// NOTE: **PDF does not use utf-8 string encoding like Go so `s` will often not be a utf-8 encoded
// string.**
func MakeString(s string) *PdfObjectString { _aaad := PdfObjectString{_gcae: s}; return &_aaad }
I want to my pdf file's 'reason' become readable cyrillic symbols,
so, is there any solutions for this ? Hope, I explained the problem ...
It should work if you use core.MakeEncodedString
https://apidocs.unidoc.io/unipdf/latest/github.com/unidoc/unipdf/v3/core/#MakeEncodedString
signature.Reason = core.MakeEncodedString("русский > Request Id = 12, Task Id = 145", true)
func MakeEncodedString(s string, utf16BE bool) *PdfObjectString
MakeEncodedString creates a PdfObjectString with encoded content, which can be either UTF-16BE or PDFDocEncoding depending on whether utf16BE is true or false respectively.
This will store the reason in UTF-16BE which is appropriate for this text.
Disclosure: I am the original developer of UniPDF.

Store a base64 image in mongodb using ReactiveGridFsTemplate Spring Webflux

Previously, i was able to store a base64 image using GridFsTemplate as below.
val imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary("base64 image string")
gridFsTemplate.store(ByteArrayInputStream(imageBytes), "imagename")
However the store() function of ReactiveGridFsTemplate takes in a parameter which is of type Flux<DataBuffer>. How can i convert a base64 image to that type?
I believe you can use AsyncStreamHelper.toAsyncInputStream with the base64 as a byte array.
I'm on my phone right now so I can't write an example, but you can check the second last method of the class here: https://github.com/BayviewComputerClub/smoothie-web/blob/master/src/main/java/club/bayview/smoothieweb/repositories/TestDataRepository.java

Google Protocol Buffer error: "Encountered string containing invalid UTF-8 data while serializing protocol buffer"

I am using the following code
int lenSend = odl->ByteSize();
char* buf = (char *)malloc(lenSend);
odl->SerializeToArray(buf, lenSend);
I get this error and I can't understand why I get it (yes I get it three times):
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
Thanks.
You can get rid of the warning by following the advice in the message!
You must have a field or fields in the definition of odl (in your .proto file) which are defined as string but into which you are putting non-UTF-8 characters. The docs state that you shouldn't do this. If you change these to bytes, the warnings should disappear.
string A string must always contain UTF-8 encoded or 7-bit ASCII text. string String str/unicode[4]
bytes May contain any arbitrary sequence of bytes. string ByteString str
somtimes you should user bytes instead of string!
Use byte[] to replace string, which encoding is not UTF-8 or ASCII.
Convert []byte for translate
Example:
message Data {
Object obj = 1;
}
If <grpc: failed to unmarshal the received message string field contains invalid UTF-8>:
# marshal object
message Data {
bytes encodeObject = 1;
}
# unmarshal object
In golang, you can use strings.ToValidUTF8 to avoid temporary

Trying to parse string from a website that gives device status with a value at the end

I'm using ruby and trying to get a value from a string that I received from an URI.PARSE.
Below is what I get back from the URI.PARSE and is in my string. You can see it in the result at the bottom. Q8:0; I only need the Device which in this case is Q8 and the value is 0. The device is always a string but sometimes the value is a string and sometimes a integer. I want to be able to evaluate this result to do events based on the values.
html code>Q8:0;html code
_, device, value, _ = "html code>Q8:0;html code".split(/[>:;]/)

Getting as3crypto to work with ruby (Gibberish/EzCrypto)

I'm trying to get as3crypto to play nice with either Gibberish or EzCrypto in AES-128 mode.
No matter what combination of settings I use I simply cannot get one to decrypt the other, and usually get a "bad decrypt" message in ruby. Each contained environment can decrypt data it encrypted itself but one cannot seem to decrypt the other.
Has anyone been able to get the two to work together?
Here's one of the variations I tried:
On the Actionscript side, using as3crypto:
//define the encryption key
var key:ByteArray = Hex.toArray("password");
//put plaintext into a bytearray
var plainText:ByteArray = Hex.toArray(Hex.fromString("this is a secret!"));
//set the encryption key
var aes:AESKey = new AESKey(key);
//encrypt the text
aes.encrypt( plainText );
trace(Base64.encode(Hex.fromArray(plainText)));
//encrypted value is N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==
And on the ruby side, using gibberish:
// also tried the default size (256)
cipher = Gibberish::AES.new("password",128)
// raises the following exception: OpenSSL::Cipher::CipherError: wrong final block length
cipher.dec("N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==")
I've tried all sort of different approaches, all yielding either the above exception or "bad encrypt"
Finally figured it out myself. The thing is both Gibberish and EzCrypto do not seem to provide a way to specify an IV, which is needed when using aes-cbc. The trick is to extract the iv from the first 16 bytes of the encrypted data as3crypto produces.
Here's the as3 code, which also changed a little:
// there are other ways to create the key, but this works well
var key:ByteArray = new ByteArray();
key.writeUTFBytes(MD5.encrypt("password"));
// encrypt the data. simple-aes-cbc is equiv. to aes-256-cbc in openssl/ruby, if your key is
// long enough (an MD5 is 32 bytes long)
var data:ByteArray = Hex.toArray(Hex.fromString("secret"));
var mode:ICipher= Crypto.getCipher("simple-aes-cbc", key) ;
mode.encrypt(data);
// the value here is base64, 32 bytes long. the first 16 bytes are the IV, needed to decrypt
// the data in ruby
// e.g: sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=
trace(Base64.encodeByteArray(data));
The ruby part uses a gem called encryptor to supply the iv.
you can also use OpenSSL directly, it's pretty straight forward:
key = Digest::MD5.hexdigest("password")
// decode the base64 encoded data back to binary:
encrypted_data = Base64.decode64("sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=")
// the tricky part: extract the IV from the decoded data
iv = encrypted_data.slice!(0,16)
// decrypt!
Encryptor.decrypt(encrypted_data,:key=>key,:iv=>iv)
// should output "secret"

Resources