Simple String Encryption and Decryption in .net(C# and VB.NET)
Hi All,
Some times we need to encrypt a string or password for some reason.For that we can use the below encryption and decryption technique. it can be used for simple and less secured strings.
C#
private string EnryptString(string strEncrypted)
{
try
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted);
string encryptedConnectionString = Convert.ToBase64String(b);
return encryptedConnectionString;
}
catch
{
throw;
}
}
private string DecryptString(string encrString)
{
try
{
byte[] b = Convert.FromBase64String(encrString);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
}
catch
{
throw;
}
}
VB.NET
Private Function EnryptString(ByVal strEncrypted As String) As String
Try
Dim b As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted)
Dim encryptedConnectionString As String = Convert.ToBase64String(b)
Return encryptedConnectionString
Catch
Throw
End Try
End Function
Private Function DecryptString(ByVal encrString As String) As String
Try
Dim b As Byte() = Convert.FromBase64String(encrString)
Dim decryptedConnectionString As String = System.Text.ASCIIEncoding.ASCII.GetString(b)
Return decryptedConnectionString
Catch
Throw
End Try
End Function
Regards
JK
Hi friend, i have error while using your Decryption function...