Dear KNR,
Try this code as this is perfectly fine for me. I hope this will help you out:-
public string EncryptString(string pwd)
{
try
{
byte[] strByte = new byte[pwd.Length];
strByte = System.Text.Encoding.UTF8.GetBytes(pwd);
string encodedPwd = Convert.ToBase64String(strByte);
return encodedPwd;
}
catch
{
return null;
}
}
public string DecryptString(string pwd)
{
try
{
UTF8Encoding encoder = new System.Text.UTF8Encoding();
Decoder utf8Decode = encoder.GetDecoder();
byte[] toDecode_byte = Convert.FromBase64String(pwd);
int charCount = utf8Decode.GetCharCount(toDecode_byte, 0, toDecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(toDecode_byte, 0, toDecode_byte.Length, decoded_char, 0);
string decodedPwd = new string(decoded_char);
return decodedPwd;
}
catch
{
return null;
}
}