Here is the code for the function and the stored procedure:
Function:
Friend Function IfRegisteredReturnDataRow(ByVal plaintextEmailAddress As
String, ByVal pass As String) As Boolean
Dim custDs As New DataSet("Customers")
custDs = SqlHelper.ExecuteDataset(connectionString(),
CommandType.StoredProcedure, "GetCustomerTable")
Dim dRow As DataRow
Dim dCol As DataColumn
Dim aes As New AesCryptClass
Dim iVByteArray As Byte()
Dim emailAddressByteArray() As Byte
Dim decryptedEmailAddress As String
Dim passByteArray() As Byte
Dim saltHsh As New SaltedHash
For Each dRow In custDs.Tables.Item(0).Rows
'Get the IV value and the encrypted email value of each row
If Not (dRow("IV").Equals(System.DBNull.Value) And
dRow("EmailAddress").Equals(System.DBNull.Value)) Then
'Dim ivSqlBinary As New SqlBinary(dRow("IV")) 'Tried
conversion with SqlBinary doesn't work either, get narrowing cast error
iVByteArray = dRow("IV") 'Doesn't work
emailAddressByteArray =
Encoding.UTF8.GetBytes(dRow("EmailAddress")) 'Doesn't work
passByteArray = Encoding.UTF8.GetBytes(dRow("Password"))
decryptedEmailAddress = aes.Decrypt(emailAddressByteArray,
iVByteArray)
If plaintextEmailAddress = decryptedEmailAddress And _
saltHsh.ComparePasswords(passByteArray,
Encoding.UTF8.GetBytes(pass)) Then
Return True
End If
End If
Next
Return False
End Function
Stored Proc:
CREATE PROCEDURE GetCustomerTable As
SELECT IV, LastName, FirstName, EmailAddress,Phone,Password,
Street,ApartmentNumber,Town,State
FROM Customers
GO
All columns except for the CustomerID column (PK) are varbinary
Frans Bouma said:
Phil said:
Miha,
That is the first thing I tried, and I get a "
Specified cast is not valid. "
error.
I tried using System.Text.Encoding.Unicode.GetBytes but that doesn't
work
strange, as SqlDataReader will return a byte[] for a varbinary...
FB
The stored procedure I use to get the table values is a simple select
statement of all the columns of the table (all the columns are
varbinary), and I'm using the old data access block with an
ExecuteDataset" "Miha Markic said:
Hi Phil,
I should be mapped to byte[] (byte array).
--
Miha Markic [MVP C#]
RightHand .NET consulting & development
www.rthand.com
Blog:
http://cs.rthand.com/blogs/blog_with_righthand/
Hi. I have a stored procedure that returns a select on a table of
sql >> server varbinary values.
The return gets bound to a datatable and when I examine a cell
value from >> the datarow level, i.e. dr("foo column") I don't know
what type the value >> is? I need to convert
dr("foo column") to a byte array.
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------