Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting data 1

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I was looking at a website that talked about encrypting passwords and such for database entry. They give the following code

<%@ Import Namespace=&quot;System.Web.Security&quot; %>
<html>
<head>
<script language=&quot;VB&quot; runat=server>
' This function encrypts the input string using the SHA1 and MD5
' encryption algorithms
Sub encryptString(Src As Object, E As EventArgs)
SHA1.Text = CookieAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, &quot;SHA1&quot;)
MD5.Text = CookieAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, &quot;MD5&quot;)
End Sub
</script>
</head>
<body>

Say I take SHA1.text and input it into a database encrypted. How would I decrypted it when pulling it back to the page. I didn't see any data on that.

 
LOL Mark.
I had the class done previously...

Daren J. Lahey
Just another computer guy...
 
Two possibly 3 ways actually.
1. bind the dropdown normally. Then loop through it and decrypt the text putting the decrypted string back in.

2. Loop through a dataset manually filling the dropdown and decrypting data as you go.

3. Use the databinding event to decrypt the data as it is bound to the drop down.

Your problem there is that your are merely binding a string to the .datatextfield.

the dataTextField property holds the name of a column in your data be it a reader or a dataset or XML structure.
shout if I lose you.
You were trying to tell it to use the column of whatever the string &quot;Name&quot; decrypts to. Which in this case is an error message since &quot;Name&quot; isn't an encrypted string.

What you need to do is decrypt the data in that column not the name of the column correct?

Anyway that is why it wasn't working That'l do donkey, that'l do
[bravo] Mark
 
Oh I see that now. You actually used the SHA encryption class for it whereas I used DES That'l do donkey, that'l do
[bravo] Mark
 
That's the beauty of the System.Security.Cryptography classes. You can choose wich kind of encryption you would like to assemble =)

Daren J. Lahey
Just another computer guy...
 
yup I quite like them. That'l do donkey, that'l do
[bravo] Mark
 
Hey Mark, as Daren used SHA and you used DES. How much change would need to be done to your Original code to use SHA
 
why change the code? Daren supplied it. I know that it is written in C# but that is part of the .NET initiative. Interlangauge usability. Just use Daren's class then send in the parameters from VB. That'l do donkey, that'l do
[bravo] Mark
 
Interlangauge usability. Just use Daren's class then send in the parameters from VB? I didn't know you could have both languages on one page???
 
uh not sure about a single page. Just create a C# class file copy paste. Make sure to include it in your project and there you go. That'l do donkey, that'l do
[bravo] Mark
 
Ah, now I understand! :) now If I could just get this decrypted text to go into a dropdown menu from my datareader I would be good to go. I think I could pull my hair out of my head.
 
Still got your hair?? That'l do donkey, that'l do
[bravo] Mark
 
yes, I do, just a little thinner now :) Of course that beer I had when I got home really helped too. :)
 
*takes a dink of &quot;Purple Star&quot; beer*

my favourite brand...

note to user:
this ad was paid in full by DJL & C.
Daren J. Lahey
Just another computer guy...
 
I was drinking the Killian's Red and Boulavard Unfiltered Wheat(Kansas City Beer). Good stuff!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top