0

this ionic app use barcode-scanner/ngx to scan qr which contain some data like these:

U2FsdGVkX18ZiW2uS4siFkyhfNNTONWKRZZ1O5PYI6CUqKcLJdv//7VxPVkwpV0L
rRz7javcch77rsCA5hcaJUNle1lxVRb3mWMHyogWpTLXdV6Oq10hstzcznwqHm4+
kgDZVXm/e6FX7JofiHH58gLVvYGSpNbCgSDcHzGzmqM+zye9QYFbLD8381zl3z88
b9p3MwwhjJZo6olXIMazcAkndbyAdgzfXJlGvs5whLeMgWtluSNnNKWkY26BfMwT
uLxvQQgzr8VjfjQ21a8cHXJEu2qrbuu0y2JkzxWvIwFLw9XjRFHn/rOlD+q1fSuO

which is the output of a aes encryption

once it scans qr it use CryptoJS to decrypt qrdata

by using a code like this

 CryptoJS.AES.decrypt(qrdata, this.secretKey.trim()).toString(CryptoJS.enc.Utf8);

but i got this error while decr

Error: Malformed UTF-8 data

i use this help: Why I get Malformed UTF-8 data error on crypto-js?

but the final code returns null or empty after decryption i check the scan qrcode output it is ok

scanCode()
{

    this.barcodeScanner.scan().then(barcodeData => {

 this.scannedCode=barcodeData.text;

 if (this.scannedCode!="" || this.scannedCode!=null)
 {

  const str = this.scannedCode;
  const info2 = crypto.AES.decrypt(str, 'secretKey').toString(crypto.enc.Utf8);
 this.dec=({ info2 });
alert("start");
    alert(this.scannedCode); ///it is ok
    alert(this.dec.info2);  // alert empty
.................
D Abasi
  • 23
  • 4

0 Answers0