crypto streams byte() to Sql Server varbinary? Possible?

  • Thread starter Thread starter Julian Stevens
  • Start date Start date
J

Julian Stevens

Can anyone definitevly tell me if I can encrypt a password
using TripleDESCryptoServiceProvider with output as a
stream in a byte[] 1-dimensional array and save it as
varbinary in SQL Server 2000? I have read that a dataset
will not support this and that a datareader might? My
code works perfectly when I directly insert the data using
a stored proc without a dataset. But when I try to use a
dataset I get an error: Inconvertable type mismatch
between SourceColumn 'UsersPassword' of Byte[] and the
DataColumn 'UsersPassword' of SqlBinary. I tried using
System.Data.SqlTypes.SqlBinary.op_Implicit(bytPassword)to
convert the array to binary, but got the same error. Is
there a work around for this?
 
Just a suggestion, but you have plenty of room to store the password as an
CypherText as a String. I've only done with the the Rijandel, but there's
plenty of room in a good old fashioned Varchar field to store the String
representation of a a 3Des Cypher unless you are encrypting some really
long stuff. Even an extra strong password will fit it you use the string
represtentation.
http://www.pune-csharp.com/news/articles/crypto/

http://www.gotdotnet.com/team/clr/samples/eula_clr_cryptosrc.aspx

These should help.

Cheers,

Bill
 
Thanx Bill for the reply! I have to store the passwords
in binary format as opposed to string for security
reasons. But that sounds like a great ideal as well.

But just to let you know, I just got my code to work. I
had to use type System.Byte() in my Business Facade,
Business Rules and Dataset [ example code for Dataset
table column: .Add(UsersPassword, GetType(System.Byte
())) ], and type SqlDbType.VarBinary in my dataadapter to
map to my SQL Server. Type System.Byte() for a 1-
dimensional byte array doesn't show up in the auto list
members dropdown box in Visual Studio, only System.Byte
does. But it is a valid type. So, I guess I answered my
own question that you can use a .NET dataset with
TripleDESCryptoServiceProvider encryption. Only took me 2
days of trial and error coding to figure it out...

Thanx!!!
-----Original Message-----
Just a suggestion, but you have plenty of room to store the password as an
CypherText as a String. I've only done with the the Rijandel, but there's
plenty of room in a good old fashioned Varchar field to store the String
representation of a a 3Des Cypher unless you are encrypting some really
long stuff. Even an extra strong password will fit it you use the string
represtentation.
http://www.pune-csharp.com/news/articles/crypto/

http://www.gotdotnet.com/team/clr/samples/eula_clr_cryptos rc.aspx

These should help.

Cheers,

Bill
Can anyone definitevly tell me if I can encrypt a password
using TripleDESCryptoServiceProvider with output as a
stream in a byte[] 1-dimensional array and save it as
varbinary in SQL Server 2000? I have read that a dataset
will not support this and that a datareader might? My
code works perfectly when I directly insert the data using
a stored proc without a dataset. But when I try to use a
dataset I get an error: Inconvertable type mismatch
between SourceColumn 'UsersPassword' of Byte[] and the
DataColumn 'UsersPassword' of SqlBinary. I tried using
System.Data.SqlTypes.SqlBinary.op_Implicit(bytPassword) to
convert the array to binary, but got the same error. Is
there a work around for this?


.
 
Excellent! I wasn't preaching by any means, just trying to make a
suggestion, but storing in Binary is defintely safer.

Glad to hear it worked.

Cheers,

Bill
Julian Stevens said:
Thanx Bill for the reply! I have to store the passwords
in binary format as opposed to string for security
reasons. But that sounds like a great ideal as well.

But just to let you know, I just got my code to work. I
had to use type System.Byte() in my Business Facade,
Business Rules and Dataset [ example code for Dataset
table column: .Add(UsersPassword, GetType(System.Byte
())) ], and type SqlDbType.VarBinary in my dataadapter to
map to my SQL Server. Type System.Byte() for a 1-
dimensional byte array doesn't show up in the auto list
members dropdown box in Visual Studio, only System.Byte
does. But it is a valid type. So, I guess I answered my
own question that you can use a .NET dataset with
TripleDESCryptoServiceProvider encryption. Only took me 2
days of trial and error coding to figure it out...

Thanx!!!
-----Original Message-----
Just a suggestion, but you have plenty of room to store the password as an
CypherText as a String. I've only done with the the Rijandel, but there's
plenty of room in a good old fashioned Varchar field to store the String
representation of a a 3Des Cypher unless you are encrypting some really
long stuff. Even an extra strong password will fit it you use the string
represtentation.
http://www.pune-csharp.com/news/articles/crypto/

http://www.gotdotnet.com/team/clr/samples/eula_clr_cryptos rc.aspx

These should help.

Cheers,

Bill
Can anyone definitevly tell me if I can encrypt a password
using TripleDESCryptoServiceProvider with output as a
stream in a byte[] 1-dimensional array and save it as
varbinary in SQL Server 2000? I have read that a dataset
will not support this and that a datareader might? My
code works perfectly when I directly insert the data using
a stored proc without a dataset. But when I try to use a
dataset I get an error: Inconvertable type mismatch
between SourceColumn 'UsersPassword' of Byte[] and the
DataColumn 'UsersPassword' of SqlBinary. I tried using
System.Data.SqlTypes.SqlBinary.op_Implicit(bytPassword) to
convert the array to binary, but got the same error. Is
there a work around for this?


.
 
Back
Top