0

I have already retrieved the bytes of arrays stored in a SQL Server database for verification purposes.

The problem is, when I convert from Base64String this error message shows up.

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

This is my code.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;

//imports
using DHELTASSys.Modules;

namespace Enrollment
{
    /* NOTE: This form is inherited from the CaptureForm,
        so the VisualStudio Form Designer may not load it properly
        (at least until you build the project).
        If you want to make changes in the form layout - do it in the base CaptureForm.
        All changes in the CaptureForm will be reflected in all derived forms 
        (i.e. in the EnrollmentForm and in the VerificationForm)
    */
    public class VerificationForm : CaptureForm
    {
        AttendanceModuleBL attendance = new AttendanceModuleBL();

        delegate void Function();

        public void Verify()
        {
            ShowDialog();
        }

        protected override void Init()
        {
            base.Init();
            base.Text = "Fingerprint Verification";
            DPFP.Verification.Verification Verificator = new DPFP.Verification.Verification();      // Create a fingerprint template verificator
            UpdateStatus(0);
        }

        protected override void Process(DPFP.Sample Sample)
        {
            int i = 0;

            int x = 3;

            DataTable dt = attendance.GetEmployeeFingerprint();


            do
            {
                string converted = dt.Rows[x][1].ToString();
                converted.Replace('-', '+');
                converted.Replace('_', '/');

                byte[] fingerprint = Convert.FromBase64String(converted);

                DPFP.Template Template = new DPFP.Template();

                Template.DeSerialize(fingerprint);

                DPFP.Verification.Verification Verificator = new DPFP.Verification.Verification();

                base.Process(Sample);

                // Process the sample and create a feature set for the enrollment purpose.
                DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);

                // Check quality of the sample and start verification if it's good
                // TODO: move to a separate task
                if (features != null)
                {
                    // Compare the feature set with our template
                    DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                    Verificator.Verify(features, Template, ref result);
                    UpdateStatus(result.FARAchieved);

                    if (result.Verified)
                    {
                        MakeReport("The fingerprint was VERIFIED.\n" + dt.Rows[x][0].ToString());
                    }
                    else
                    {
                        MakeReport("The fingerprint was NOT VERIFIED.");
                        x++;
                    }
                }
            } while (i == 0);
        }

        private void UpdateStatus(int FAR)
        {
            // Show "False accept rate" value
            SetStatus(String.Format("False Accept Rate (FAR) = {0}", FAR));
        }
    }
}

I have stored the fingerprint template to SQL Server earlier using this code:

MemoryStream fingerprintData = new MemoryStream();
Template.Serialize(fingerprintData);
fingerprintData.Position = 0;
BinaryReader br = new BinaryReader(fingerprintData);
byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);

I don't seem to know a workaround in this issue.

Thanks in advance!

sjakobi
  • 3,546
  • 1
  • 25
  • 43
heyitsmarcucu
  • 612
  • 5
  • 9

1 Answers1

0

On one side, I see Convert.FromBase64String.

On the other side, I do not see Convert.ToBase64String.

Your error message complains about invalid Base64 characters. The normal Base64 character set is a-zA-Z0-9+/ with = padding. The next most common uses - and _ instead of + and / (and usually doesn't have padding.

Look at your actual data in hex - do you have characters other than what your Base64 function expects? Do you need to Base64 encode it first, or perhaps you don't need to Base64 encode it at all?

Read up on Base64.

Anti-weakpasswords
  • 2,604
  • 20
  • 25