我已经检索了存储在SQL Server数据库中的数组字节以进行验证。
问题是,当我从Base64String
转换时,会显示此错误消息。
输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。
这是我的代码。
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));
}
}
}
我之前使用以下代码将指纹模板存储到SQL Server:
MemoryStream fingerprintData = new MemoryStream();
Template.Serialize(fingerprintData);
fingerprintData.Position = 0;
BinaryReader br = new BinaryReader(fingerprintData);
byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);
我似乎不知道这个问题的解决方法。
提前致谢!
答案 0 :(得分:0)
一方面,我看到Convert.FromBase64String。
另一方面,我没有看到Convert.ToBase64String。
您的错误消息会抱怨Base64字符无效。普通的Base64字符集是a-zA-Z0-9 + / with = padding。接下来最常见的用途 - 和_而不是+和/(并且通常没有填充。
以十六进制的形式查看实际数据 - 除了Base64函数的预期之外,您是否还有其他字符?您是否需要先对Base64进行编码,或者您根本不需要对Base64进行编码?
阅读Base64。