encrypt and decrypt password using asp.net with C#
encrypt function
private string encryp(string password)
{
string msg = string.Empty;
byte[] encode = new byte[password.Length];
encode = Encoding.UTF8.GetBytes(password);
msg = Convert.ToBase64String(encode);
return msg;
}
Decrypt function
private string decrypt(string encrypt)
{
string decryp = string.Empty;
UTF8Encoding encodedpass = new UTF8Encoding();
Decoder decode = encodedpass.GetDecoder();
byte[] todecodedbyte = Convert.FromBase64String(encrypt);
int charcount = decode.GetCharCount(todecodedbyte, 0, todecodedbyte.Length);
char[] dechodedchar = new char[charcount];
decode.GetChars(todecodedbyte, 0, todecodedbyte.Length, dechodedchar, 0);
decryp = new string(dechodedchar);
return decryp;
}
private string encryp(string password)
{
string msg = string.Empty;
byte[] encode = new byte[password.Length];
encode = Encoding.UTF8.GetBytes(password);
msg = Convert.ToBase64String(encode);
return msg;
}
Decrypt function
private string decrypt(string encrypt)
{
string decryp = string.Empty;
UTF8Encoding encodedpass = new UTF8Encoding();
Decoder decode = encodedpass.GetDecoder();
byte[] todecodedbyte = Convert.FromBase64String(encrypt);
int charcount = decode.GetCharCount(todecodedbyte, 0, todecodedbyte.Length);
char[] dechodedchar = new char[charcount];
decode.GetChars(todecodedbyte, 0, todecodedbyte.Length, dechodedchar, 0);
decryp = new string(dechodedchar);
return decryp;
}
0 comments :