System.Security.Cryptography.CryptographicException: Bad Data. 
Author Message
 System.Security.Cryptography.CryptographicException: Bad Data.

Using
FormAuthentication.HashPasswordForStoringInConfigFile()
method, I am able to hash a password. However, I get this
exception "System.Security.Cryptography.CryptographicExcep
tion: Bad Data.", when I use the Decrypt method of the
FormAuthentication Ticket class.

Dim oFormAuth As New FormsAuthentication()
Dim oFormsAuthTicket As FormsAuthenticationTicket
Dim sTicket As String
Dim sHashPWD As String

' -------------- Works fine --------------------
sHashPWD = oFormAuth.HashPasswordForStoringInConfigFile
(Me.TextBox1.Text, "sha1")

Me.TextBox2.Text = sHashPWD
' -------------- Works fine --------------------

' Exception at Decrypt() method call.
oFormsAuthTicket = oFormAuth.Decrypt(Me.TextBox2.Text)
sTicket = oFormsAuthTicket.UserData

Any response is appreciated.

Thanks

MK



Mon, 27 Jun 2005 00:24:41 GMT  
 System.Security.Cryptography.CryptographicException: Bad Data.
You cannot decrypt a hash, its a oneway process only.

Once a password is hashed you compare the "given" password (hashed) to the
existing hash.

Use pub/priv key encryption if you want to decrypt.

Craig


Quote:
> Using
> FormAuthentication.HashPasswordForStoringInConfigFile()
> method, I am able to hash a password. However, I get this
> exception "System.Security.Cryptography.CryptographicExcep
> tion: Bad Data.", when I use the Decrypt method of the
> FormAuthentication Ticket class.

> Dim oFormAuth As New FormsAuthentication()
> Dim oFormsAuthTicket As FormsAuthenticationTicket
> Dim sTicket As String
> Dim sHashPWD As String

> ' -------------- Works fine --------------------
> sHashPWD = oFormAuth.HashPasswordForStoringInConfigFile
> (Me.TextBox1.Text, "sha1")

> Me.TextBox2.Text = sHashPWD
> ' -------------- Works fine --------------------

> ' Exception at Decrypt() method call.
> oFormsAuthTicket = oFormAuth.Decrypt(Me.TextBox2.Text)
> sTicket = oFormsAuthTicket.UserData

> Any response is appreciated.

> Thanks

> MK



Mon, 27 Jun 2005 01:04:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. System.Security.Cryptography

2. Bad data in cryptography while closing memory stream.

3. Unhandled Exception: System.Configuration.ConfigurationException: Could not create System Configuration.NameValueSectionHandler, System

4. Getting this when run from mapped drive System.Security.Permissions.SecurityPermission

5. System.Security.SecurityException

6. System.Data.SqlClient.SqlException: Error converting data type varchar to numeric

7. System.Security.SecurityException

8. DataTable::Select and System.Data.VersionNotFoundException

9. what is [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\RNG]

10. ? HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\LEGACY_

11. System.Runtime.InteropServices.VTableCallsNotSupportedException

12. word - automatic numbering/bold/underline/italics

 

 
Powered by phpBB® Forum Software