我有一些接受許可證加密密鑰的應用程序。所以這個應用程序應該保留在string encryptionPassword
之內,以便解密該字符串並獲取一些數據。如何在應用程序中保留加密密碼?
哪個是最好的方法來保持string encryptionPassword
在應用程序的內部,所以如果用戶會試圖破解它,它應該是非常困難的?
任何線索?
謝謝!!!
public static string Encrypt(string textToEncrypt, string encryptionPassword)
{
var algorithm = GetAlgorithm(encryptionPassword);
byte[] encryptedBytes;
using (ICryptoTransform encryptor = algorithm.CreateEncryptor(algorithm.Key, algorithm.IV))
{
byte[] bytesToEncrypt = Encoding.UTF8.GetBytes(textToEncrypt);
encryptedBytes = InMemoryCrypt(bytesToEncrypt, encryptor);
}
return Convert.ToBase64String(encryptedBytes);
}
public static string Decrypt(string encryptedText, string encryptionPassword)
{
var algorithm = GetAlgorithm(encryptionPassword);
byte[] descryptedBytes;
using (ICryptoTransform decryptor = algorithm.CreateDecryptor(algorithm.Key, algorithm.IV))
{
byte[] encryptedBytes = Convert.FromBase64String(encryptedText);
descryptedBytes = InMemoryCrypt(encryptedBytes, decryptor);
}
return Encoding.UTF8.GetString(descryptedBytes);
}
一個足夠確定的用戶將設法讀取這樣一個密碼 - 它可能需要時間和精力,但它是可能的。 – Oded
另外 - 請參閱[SecureString](http://msdn.microsoft.com/en-us/library/system.security.securestring.aspx)。 – Oded
@Oded比你!但是我無法使用.NET 4.5 –