我不知道如何开始,但我想知道我该如何测试我的程序的安全性,特别是我刚刚复制到MSDN上的AES应用程序。
我不是应用程序安全方面的专家,也不了解安全问题。
如果有软件自动为我做这件事,那就更好了。
这是我复制的代码:
static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
byte[] encrypted;
// Create an AesManaged object
// with the specified key and IV.
using (AesManaged aesAlg = new AesManaged())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for encryption.
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
//Write all data to the stream.
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}发布于 2017-03-23 08:05:07
该代码只使用AES/CBC。为静态数据提供保密性是很好的。像往常一样,它会泄漏有关输入长度的信息。
此外,它不提供完整性或真实性,因此任何人都可以更改密文。这意味着如果这是一个有效的攻击场景,部分明文将被篡改。
它本身并不在传输协议中提供任何保护。由于填充oracle攻击,甚至很容易泄漏整个明文。
密钥应该使用密码散列(例如PBKDF2 )从密码派生,或者应该随机生成。
如果您为CBC重用密钥,那么IV应该是不可预测的(通过使用安全的随机生成器)。IV通常放在密文的前面。
代码没有显示这些属性中的任何一个。
换句话说,这在很大程度上取决于上面的代码是否安全,以及可能的攻击向量。AES是安全的,但这本身并不提供任何保护。
代码是AES/CBC,没有更多也没有更少。如果你不理解加密,并且你复制代码,即使是从微软,机会是微乎其微的,你将结束与任何一种安全。
https://stackoverflow.com/questions/42963443
复制相似问题