Reputation: 13
I am trying to decrypt my password stored in aspnet_membership
table...
I am using the following code,
Dim encodedPassword() As Byte = System.Text.Encoding.UTF8.GetBytes(password)
encodedPassword = MyBase.EncryptPassword(encodedPassword)
Dim decryptedPassword() As Byte = MyBase.DecryptPassword(encodedPassword)
If (decryptedPassword IsNot Nothing) Then
Return System.Text.Encoding.UTF8.GetString(decryptedPassword, 0, decryptedPassword.Length)
End If
but at the line of DecryptPassword(encodedPassword)
it shows error as
"Length of the data to decrypt is invalid."
Upvotes: 1
Views: 2013
Reputation: 29811
I think you need to Base64 Decode it first:
byte[] encodedPassword = Convert.FromBase64String(pass);
byte[] bytes = this.DecryptPassword(encodedPassword);
or in VB.NET:
Dim encodedPassword As Byte() = Convert.FromBase64String(pass)
Dim bytes As Byte() = Me.DecryptPassword(encodedPassword)
Edit: As @Eranga pointed out, this is provided that the MembershipProvider used actually supports decryption and for the default provider the passwordFormat setting controls if it's "hashed", "encrypted" or "plain". By default the setting is "hashed", which means no decryption possible.
Encrypted passwords are base64 encoded before being saved to the database and for that reason they need to be decoded before being decrypted.
Upvotes: 1