P
Phil C.
I've been having trouble getting a byte array back as a datatable column
with this code:
Public Class RegisteredCustomerVerify
''' -----------------------------------------------------------------------------
''' <summary>
''' Friend Function ValidEmail
''' Pass plaintext email address to stored proc that must use
''' aes key and decrypt each row of customer table and compare the
''' email address to the passed email
''' </summary>
''' <param name="plaintextEmailAddress"></param>
''' <returns>Returns True (email match) or False (no Email
match)</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [SmallFry] 9/17/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Function IfRegistered(ByVal plaintextEmailAddress As String,
ByVal pass As String) As Boolean
Dim custDs As New DataSet
'custDs = SqlHelper.ExecuteDataset(connectionString(),
CommandType.StoredProcedure, "GetCustomerTable")
Dim cn As New SqlConnection(connectionString())
Dim cmd As New SqlDataAdapter
cmd.SelectCommand = New SqlCommand
With cmd.SelectCommand
.Connection = cn
.CommandText = "GetCustomerTable"
.CommandType = CommandType.StoredProcedure
End With
cmd.Fill(custDs, "Customers")
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"))
Dim type As Type = dRow.Table.Columns("IV").DataType()
type.ToString()
iVByteArray = dRow("IV")
emailAddressByteArray =
Encoding.UTF8.GetBytes(dRow("EmailAddress"))
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
In the debugger (code in asterisked section below), I am getting the table
"item" as <cannot view indexed property>
which led me to read this article:
http://dotnet247.com/247reference/msgs/17/86113.aspx
which states:
Mark Miller
There's a subtle problem with your code. The Rows property of a
DataTable
returns a DataRowCollection, not a DataRow. The indexer you are
attempting
to use ([0, DataRowVersion.Current]) only exists in DataRow. Further
this
indexer returns an object, as in row["columnName"] (ie. a column
value), not
a DataRow.
The only indexer in DataRowCollection is DataRow this[int index]
{get;}.
So, the correct way to write your code would be:
string fieldValue = updateDataSet.Tables[0].Rows[0][0,
DataRowVersion.Current];
This will return the current version of the value in the first column,
in
the first row, of the first table.
--
---Mark
but I think I am doing it correctly.
Any ideas would be appreciated.
Below is the expanded tree from my debugger window on the datatable:
******************************************************************
- custDs {System.Data.DataSet} System.Data.DataSet
CaseSensitive False Boolean
Container Nothing System.ComponentModel.IContainer
DataSetName "NewDataSet" String
+ DefaultViewManager {System.Data.DataViewManager}
System.Data.DataViewManager
DesignMode False Boolean
EnforceConstraints True Boolean
+ ExtendedProperties {System.Data.PropertyCollection}
System.Data.PropertyCollection
HasErrors False Boolean
+ Locale {System.Globalization.CultureInfo}
System.Globalization.CultureInfo
Namespace "" String
Prefix "" String
+ Relations
{System.Data.DataRelationCollection.DataSetRelationCollection}
System.Data.DataRelationCollection
Site Nothing System.ComponentModel.ISite
- Tables {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
+ [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
<cannot view indexed property> Expression expected.
+ custDs.Tables {System.Data.DataTableCollection}
System.Data.DataTableCollection
*********************************************************************************************
with this code:
Public Class RegisteredCustomerVerify
''' -----------------------------------------------------------------------------
''' <summary>
''' Friend Function ValidEmail
''' Pass plaintext email address to stored proc that must use
''' aes key and decrypt each row of customer table and compare the
''' email address to the passed email
''' </summary>
''' <param name="plaintextEmailAddress"></param>
''' <returns>Returns True (email match) or False (no Email
match)</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [SmallFry] 9/17/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Function IfRegistered(ByVal plaintextEmailAddress As String,
ByVal pass As String) As Boolean
Dim custDs As New DataSet
'custDs = SqlHelper.ExecuteDataset(connectionString(),
CommandType.StoredProcedure, "GetCustomerTable")
Dim cn As New SqlConnection(connectionString())
Dim cmd As New SqlDataAdapter
cmd.SelectCommand = New SqlCommand
With cmd.SelectCommand
.Connection = cn
.CommandText = "GetCustomerTable"
.CommandType = CommandType.StoredProcedure
End With
cmd.Fill(custDs, "Customers")
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"))
Dim type As Type = dRow.Table.Columns("IV").DataType()
type.ToString()
iVByteArray = dRow("IV")
emailAddressByteArray =
Encoding.UTF8.GetBytes(dRow("EmailAddress"))
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
In the debugger (code in asterisked section below), I am getting the table
"item" as <cannot view indexed property>
which led me to read this article:
http://dotnet247.com/247reference/msgs/17/86113.aspx
which states:
Mark Miller
There's a subtle problem with your code. The Rows property of a
DataTable
returns a DataRowCollection, not a DataRow. The indexer you are
attempting
to use ([0, DataRowVersion.Current]) only exists in DataRow. Further
this
indexer returns an object, as in row["columnName"] (ie. a column
value), not
a DataRow.
The only indexer in DataRowCollection is DataRow this[int index]
{get;}.
So, the correct way to write your code would be:
string fieldValue = updateDataSet.Tables[0].Rows[0][0,
DataRowVersion.Current];
This will return the current version of the value in the first column,
in
the first row, of the first table.
--
---Mark
but I think I am doing it correctly.
Any ideas would be appreciated.
Below is the expanded tree from my debugger window on the datatable:
******************************************************************
- custDs {System.Data.DataSet} System.Data.DataSet
CaseSensitive False Boolean
Container Nothing System.ComponentModel.IContainer
DataSetName "NewDataSet" String
+ DefaultViewManager {System.Data.DataViewManager}
System.Data.DataViewManager
DesignMode False Boolean
EnforceConstraints True Boolean
+ ExtendedProperties {System.Data.PropertyCollection}
System.Data.PropertyCollection
HasErrors False Boolean
+ Locale {System.Globalization.CultureInfo}
System.Globalization.CultureInfo
Namespace "" String
Prefix "" String
+ Relations
{System.Data.DataRelationCollection.DataSetRelationCollection}
System.Data.DataRelationCollection
Site Nothing System.ComponentModel.ISite
- Tables {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
- [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
Count 1 Integer
IsReadOnly False Boolean
IsSynchronized False Boolean
Item <cannot view indexed property> System.Data.DataTable
- SyncRoot {System.Data.DataTableCollection} Object
+ [System.Data.DataTableCollection] {System.Data.DataTableCollection}
System.Data.DataTableCollection
<cannot view indexed property> Expression expected.
+ custDs.Tables {System.Data.DataTableCollection}
System.Data.DataTableCollection
*********************************************************************************************