public static string EncryptPassword(string sPASSWORD, Guid gKEY, Guid gIV)
{
UTF8Encoding utf8 = new UTF8Encoding(false);
string sResult = null;
byte[] byPassword = utf8.GetBytes(sPASSWORD);
using ( MemoryStream stm = new MemoryStream() )
{
Rijndael rij = Rijndael.Create();
rij.Key = gKEY.ToByteArray();
rij.IV = gIV.ToByteArray();
using ( CryptoStream cs = new CryptoStream(stm, rij.CreateEncryptor(), CryptoStreamMode.Write) )
{
cs.Write(byPassword, 0, byPassword.Length);
cs.FlushFinalBlock();
cs.Close();
}
sResult = Convert.ToBase64String(stm.ToArray());
}
return sResult;
}
public static string DecryptPassword(string sPASSWORD, Guid gKEY, Guid gIV)
{
UTF8Encoding utf8 = new UTF8Encoding(false);
string sResult = null;
byte[] byPassword = Convert.FromBase64String(sPASSWORD);
using ( MemoryStream stm = new MemoryStream() )
{
Rijndael rij = Rijndael.Create();
rij.Key = gKEY.ToByteArray();
rij.IV = gIV.ToByteArray();
using ( CryptoStream cs = new CryptoStream(stm, rij.CreateDecryptor(), CryptoStreamMode.Write) )
{
cs.Write(byPassword, 0, byPassword.Length);
cs.Flush();
cs.Close();
}
byte[] byResult = stm.ToArray();
sResult = utf8.GetString(byResult, 0, byResult.Length);
}
return sResult;
}