Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. printing encrypted byte array to a barcode and scan

printing encrypted byte array to a barcode and scan

Scheduled Pinned Locked Moved C#
data-structuressalesperformancequestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bttds
    wrote on last edited by
    #1

    I need to print encrypted customer details as a barcode. then need to scan the data and read back the details. My approch is like this, I encrypted the string data using cryptoservices and get memory stream and sen the byte array data as unmanaged byte arra to the printer. Byte[] bytes = memoryStream.GetBuffer(); IntPtr pUnmanagedBytes = new IntPtr(0); int nLength; nLength = Convert.ToInt32(memoryStream.Length); pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength); Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength); PrintDirect.WritePrinter1(lhPrinter, pUnmanagedBytes, nLength, out pcWritten); How can I read this data back to managed byte array from the scan device. (BTW am I in the correct path.)

    C 1 Reply Last reply
    0
    • B bttds

      I need to print encrypted customer details as a barcode. then need to scan the data and read back the details. My approch is like this, I encrypted the string data using cryptoservices and get memory stream and sen the byte array data as unmanaged byte arra to the printer. Byte[] bytes = memoryStream.GetBuffer(); IntPtr pUnmanagedBytes = new IntPtr(0); int nLength; nLength = Convert.ToInt32(memoryStream.Length); pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength); Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength); PrintDirect.WritePrinter1(lhPrinter, pUnmanagedBytes, nLength, out pcWritten); How can I read this data back to managed byte array from the scan device. (BTW am I in the correct path.)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What is PrintDirect ? Is it a class for printing barcodes ? I'd assume that the same class would know how to return a byte array from the barcode it created ?

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      B 1 Reply Last reply
      0
      • C Christian Graus

        What is PrintDirect ? Is it a class for printing barcodes ? I'd assume that the same class would know how to return a byte array from the barcode it created ?

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        B Offline
        B Offline
        bttds
        wrote on last edited by
        #3

        PrintDirect.writePrinter - normal pront command to write data to the printer. Theres a scan divice configured to a com port to scan the barcode. When i scan the barcode I need to read that data (that I send as unmanaged byte array to the printer). and decrypt it and get the initial customer details.

        C 1 Reply Last reply
        0
        • B bttds

          PrintDirect.writePrinter - normal pront command to write data to the printer. Theres a scan divice configured to a com port to scan the barcode. When i scan the barcode I need to read that data (that I send as unmanaged byte array to the printer). and decrypt it and get the initial customer details.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          OK, so you have two problems 1 - write a barcode that your scanner can read back 2 - read it back Assuming you got 1 right, 2 should just be a case of using the APIs provided by the scanner.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          B 1 Reply Last reply
          0
          • C Christian Graus

            OK, so you have two problems 1 - write a barcode that your scanner can read back 2 - read it back Assuming you got 1 right, 2 should just be a case of using the APIs provided by the scanner.

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            B Offline
            B Offline
            bttds
            wrote on last edited by
            #5

            everything works fine if I send my data as a string (print the barcode and read it back). Problem occures when I print it as an unmanaged byte array. Is there any way that I can send byte by byte to the printer and when scan it read byte by byte. Can anybody help me.

            C L 2 Replies Last reply
            0
            • B bttds

              everything works fine if I send my data as a string (print the barcode and read it back). Problem occures when I print it as an unmanaged byte array. Is there any way that I can send byte by byte to the printer and when scan it read byte by byte. Can anybody help me.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              REalistically, we're just stabbing in the dark, because we have no idea what bar code system/scanner you are using. You may be hitting a limitation of the SDK, if you're finding a way to write a barcode, but that barcode cannot be read back.

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              1 Reply Last reply
              0
              • B bttds

                everything works fine if I send my data as a string (print the barcode and read it back). Problem occures when I print it as an unmanaged byte array. Is there any way that I can send byte by byte to the printer and when scan it read byte by byte. Can anybody help me.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Hi, I expect a barcode printer to accept printable text only, not just arbitrary bytes. It probably will have trouble with non-printable characters. One possible solution could be to use an encoding such as base64 (which replaces a number of bytes by a greater number of ASCII-printable bytes, about 4 four 3). Have a look at Convert.ToBase64String and Convert.FromBase64String :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                B 1 Reply Last reply
                0
                • L Luc Pattyn

                  Hi, I expect a barcode printer to accept printable text only, not just arbitrary bytes. It probably will have trouble with non-printable characters. One possible solution could be to use an encoding such as base64 (which replaces a number of bytes by a greater number of ASCII-printable bytes, about 4 four 3). Have a look at Convert.ToBase64String and Convert.FromBase64String :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                  B Offline
                  B Offline
                  bttds
                  wrote on last edited by
                  #8

                  yes, the printer doesn't seems like accepting some characters. I've solved the problem by using different encryption/decryption method with no overhead (abandon the dot net cryptoservice ). Thanks alot for your comments. they help me to find the correct path.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups