Question database encryption

developer_mahmoud

Well-known member
Joined
Nov 13, 2010
Messages
64
Programming Experience
1-3
hi every body
1- if i have aform with 5 textboxes for example connected to data base how can i encrypt it to save it in the database and how can i decrypt it when i call it from the data base ?
2- if i have many sql queries like sum insert avreage with conditions how can i make it with the encrypted data?
thank u and i need help
 
If you were to encrypt data stored in a database it would only be the text. There's not much point encrypting numbers, and it's numbers that you would be performing aggregate functions on, so there's no problem.
 
thank u for ur help but i need to decrypt those text when i retrieve it in the form like a grid view or text boxes and also how can encrypt it when i save it in a database if is there any simple application plz attach it
 
The database doesn't know or care about encryption. It simply saves the data you tell it to save. If you want to save encrypted data then you encrypt it and then save the result in the database. After you retrieve the data from the database you decrypt it.

The .NET Framework has an entire namespace dedicated to encryption, i.e. System.Security.Cryptography. You must not have made any effort at all to find information because there's plenty out there.

encrypt text vb.net - Google Search
 
its so hard for me to find it iam just need asimple code to encrypt two textbox before inserting its value in ms acces databse and the codes of decrypt them when i show it in textbox or a grid view plz help
 
Developer_mahmoud, jmcilhinney has given you a link to a Google search that gives you some very good resources on doing Encryption in VB.NET. You can also have a look on my website SatalKeto.co.uk I have at least one article on there about encryption in VB.NET.
From what jmcilhinney has given you (or using the encryption stuff from my website) you should be able to do what you need. If there is something specific you're struggling with, then specify what it is rather than just saying it is hard, we wont write the code for you.
 
dear satal
iam not that lazy beblieve me i searshed alot but honestly i didnt found adata base encryption code its all about how to encrypt and decrypt password and a string text box but wat i want is how to decrypt a grid view or abinding textboxes basicly i have afield called item name i encrypt this field but when i show it in a grid view or even a textboxes i cant decrypt it thats all any way thank u for ur help
 
You wouldn't decrypt a GridView you would decrypt the data and then load it into the GridView, so by filling a DataTable then decrypting the entries that have been encrypted (which would usually be all entries in a particular column). The same go for the TextBoxes, you would get the data from the database, decrypt it and then put it into the TextBox. When saving you would read the TextBox, encrypt it then save it to the database.
 
thank u very much


Private lbtVector() As Byte = {240, 3, 45, 29, 0, 76, 173, 59}
Private lscryptoKey As String = "ChangeThis!"

'Author : Nikhil Gupta
'Description : This function encrypts a given string
'Parameters : String
'Return Values: Encrypted String
'Called From : Business Layer

'Encrypt String
Public Function psEncrypt(ByVal sInputVal As String) As String
Dim loCryptoClass As New TripleDESCryptoServiceProvider
Dim loCryptoProvider As New MD5CryptoServiceProvider
Dim lbtBuffer() As Byte

Try
lbtBuffer = System.Text.Encoding.ASCII.GetBytes(sInputVal)
loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey))
loCryptoClass.IV = lbtVector
sInputVal = Convert.ToBase64String(loCryptoClass.CreateEncryptor().TransformFinalBlock(lbtBuffer, 0, lbtBuffer.Length()))
psEncrypt = sInputVal
Catch ex As CryptographicException
Throw ex
Catch ex As FormatException
Throw ex
Catch ex As Exception
Throw ex
Finally
loCryptoClass.Clear()
loCryptoProvider.Clear()
loCryptoClass = Nothing
loCryptoProvider = Nothing
'Pass the encrypted strings to text box
txtEncryptedData.Text = sInputVal
End Try

'Pass the encrypted strings to text box
Return sInputVal
End Function

'Function to Decrypt Strings
Public Function psDecrypt(ByVal sQueryString As String) As String

Dim buffer() As Byte
Dim loCryptoClass As New TripleDESCryptoServiceProvider
Dim loCryptoProvider As New MD5CryptoServiceProvider

Try

buffer = Convert.FromBase64String(sQueryString)
loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey))
loCryptoClass.IV = lbtVector
Return Encoding.ASCII.GetString(loCryptoClass.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length()))
Catch ex As Exception
Throw ex
Finally
loCryptoClass.Clear()
loCryptoProvider.Clear()
loCryptoClass = Nothing
loCryptoProvider = Nothing
End Try

'show the decrypted data
Return sQueryString

this code working normally with me but it just encrypt and decrypt english language wat about if ineed other language like arabic
another question wat will be the code by these functions to decrypt the textbox 1 for example before iget it from the database and the grid view if u dont mind i know iam disturbing u but so sorry
 
When you code please use the code tags, it makes your code actually readable. You can do the code tags like
VB.NET:
[code ][/code ]
(you will need to remove the spaces before the "]")

I've never done anything with other languages, but I would assume that changing the code from using ASCII to UTF8 should work, but you will have to test it out as while I believe UTF8 has support for other languages I could be wrong.
 
no it doesnt work
but satal u dont answer my second question
wat will be the code by these functions to decrypt the textbox 1 for example before iget it from the database and the grid view if u dont mind
 
no it doesnt work
What doesn't work? Are you not able to use UTF8? Does UTF8 not support Arabic? Be more specific with your response!

I don't remember seeing that question, but ow well. As I mentioned before for the TextBox you would get the encrypted string from the database, then if you have a look at the code you posted, you might notice that there is a decrypt function, perhaps you could use something like that to decrypt the encrypted string, then put it in the TextBox. The GridView you would get a DataTable of the information that you want from the database, then you would go through each row in that DataTable, decrypting the value in a manner which would be reminisent of the TextBox, then you would use the DataTable with the decrypted entries as the DataSource for the GridView.

If you don't know how to get the information from the database then Google it, there are a plethora of tutorials on the Internet, which will show you how to do it. If you're unable to do that then perhaps you should try and do something a bit easier.
 
thank u satal 4 ur help
UTF8 not support arabic
and about my encryptoin question u want me to searsh on google basicly u know that this forumsis to learn and to help each other i searched in google but invain any way thank u so much for ur help
 
i will test it again
my second question i have afield called item name and i work with dataset and i have afunction called decrypt so to decrypt that field in ther datagridview first i will show the gridview then i will use this code
[decrypt(datagridview1.columns(itemname)]
is it right?
 
Back
Top