Ask a Question related to ASP.NET Security, Design and Development.
-
JC #1
TriplesDes corrputing in SQL database
Hi,
I have had a couple of postings regarding this topic already and some
very helpfull advice for which I am very gratefull indeed.
However, I am still getting some really odd behaviour from my
encryption routines. As an overview I have one function that takes a
string and encrypts it (thank you Jon for help here). Another function
that accepts byte[] and decrypts it. These two functions (below)
appear to work reliably. However, when I store the results of the
encrypt function in a SQL database (varbinary 128) then try to decrypt
it, the results are not reliable.
For example, sometimes the decryption is fine, then with exactly the
same data in the database it will error with 'bad data', then
sometimes it will jumble the result. I am only encrypting 4 characters
so varbinary 128 is large enough, and the results are being brought
back in a dataset, then into a DataRow, then the items I need
decypingting are passed to the function. But, for instance, just now I
loaded the web page and intially the results errored, then with a page
refresh it all worked fine.
Totally confused so help would be so appreciated.
James
public Byte[] myEncrypt(string sInput)
{
Byte[] inputBytes = Encoding.UTF8.GetBytes(sInput);
TripleDESCryptoServiceProvider tdesProvider = new
TripleDESCryptoServiceProvider();
ICryptoTransform cryptoTransform =
tdesProvider.CreateEncryptor(tripleDes.Key,tripleD es.IV);
MemoryStream encryptedStream = new MemoryStream();
CryptoStream cryptStream = new
CryptoStream(encryptedStream,cryptoTransform,Crypt oStreamMode.Write);
cryptStream.Write(inputBytes,0,inputBytes.Length);
cryptStream.FlushFinalBlock();
encryptedStream.Position = 0;
Byte[] bResult = encryptedStream.ToArray();
cryptStream.Close();
return bResult;
}
public string myDecrypt(Byte[] inputInBytes)
{
try
{
TripleDESCryptoServiceProvider tdesProvider = new
TripleDESCryptoServiceProvider();
ICryptoTransform cryptoTranform =
tdesProvider.CreateDecryptor(tripleDes.Key,tripleD es.IV);
MemoryStream decryptedStream = new MemoryStream();
CryptoStream cryptStream = new
CryptoStream(decryptedStream,cryptoTranform,Crypto StreamMode.Write);
cryptStream.Write(inputInBytes,0,inputInBytes.Leng th);
cryptStream.FlushFinalBlock();
decryptedStream.Position=0;
Byte[] result = decryptedStream.ToArray();
//Byte[] result = new Byte[decryptedStream.Length];
//decryptedStream.Read(result,0,decryptedStream.ToAr ray().Length);
cryptStream.Close();
return Encoding.UTF8.GetString(result).ToString();
}
catch(Exception ex)
{
return "error";
}
}
JC Guest
-
removing database alias when database doesn't exist
hi all, got a small problem here Running db/2 8.1 fp3 on a linux system. Tried to create a database called radius which seemed to work from the... -
Import Data from flat-database to relational-database
Before I start I need some tips and pleas excuse my bad english. I have two databases, one is flat and one is a relational database. example ... -
NEWBIE HELP Import Data from flat-database to relational-database
I want to import Data from a simple Database, which contains all Information in one big record into a relational Database and split up the big... -
Passing database info to page allow user input then pass into another database
Hi I really am going crazy! I'm using VBScript, ASP, and SQL My page reminds me of a shopping cart but looking at shopping cart examples has not... -
Another user has modified the contents of this table or view; the database row you are modifying no longer exists in the database;
Hi, I am testing a trigger that and I am getting this error message saying "Another user has modified the contents of this table or view; the...



Reply With Quote

