Hello,
I'm using the below article to encrypt/decrypt password.
http://www.aspsnippets.com/Articles/Encrypt-and-Decrypt-Username-or-Password-stored-in-database-in-ASPNet-using-C-and-VBNet.aspx
When I deploy the application on my local IIS its working fine. But when I deploy the same project on a Hosting Server(mywindowshosting.com) I get an error "The input data is not a complete block". Below is my code and web.config file. Does anyone got this issue before please let me know.
Web.Config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Burger_CountyConnectionStringLocal" connectionString="Data Source=sql5009.mywindowshosting.com;Initial Catalog=xxx ; Integrated Security=false; User Id=xxx; Password=xxx; MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="login.aspx" timeout="600" slidingExpiration="true"></forms>
</authentication>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<defaultDocument>
<files>
<add value="login.aspx"/>
</files>
</defaultDocument>
</system.webServer>
<machinekey validationkey="1234567890123456789012345678901234567890AAAAAAAAAA" decryptionKey="123456789012345678901234567890123456789012345678"
validation="SHA1" decryption="Auto" />
</configuration>
C# Code :
public string Decrypt(string cipherText)
{
string EncryptionKey = "MAKV2SPBNI99212";
byte[] cipherBytes = Convert.FromBase64String(cipherText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return cipherText;
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string UserName, Password;
UserName = txtUserName.Value.Trim().ToLower();
try
{
DataTable dt = UserBAL.GetUserLoginDetails(UserName);
if (dt != null && dt.Rows.Count > 0)
{
string DecryptedPassword = Decrypt(dt.Rows[0]["user_password"].ToString());
Password = txtPwd.Value.Trim().ToLower();
if (Password == DecryptedPassword)
{
--------
}