我对安全和加密这一话题非常陌生。我们的软件必须符合FIPS 140-2.我有以下方法(C#)。在这种情况下,算法是AES256。我关心的是,我们使用SHA1来散列密钥。在这里使用SHA1是可以接受的,还是破坏了FIPS的遵从性?
谢谢!
public static ServiceEncryptionKey CreateNew(ServiceEncryptionAlgorithm algorithm)
{
byte[] keyData;
using (var key = CreateSymmetricAlgorithm(algorithm))
{
key.GenerateKey();
keyData = key.Key;
}
byte[] keyHash;
using (SHA1Cng sha = new SHA1Cng())
{
keyHash = sha.ComputeHash(keyData);
}
try
{
return new ServiceEncryptionKey(algorithm, new ProtectedBytes(keyData), keyHash);
}
finally
{
Array.Clear(keyData, 0, keyData.Length);
}
}
private ServiceEncryptionKey(ServiceEncryptionAlgorithm algorithm, ProtectedBytes keyData, byte[] keyHash)
{
this.Algorithm = algorithm;
this.protectedKeyData = keyData;
this.header = new byte[16 + keyHash.Length];
this.KeyHash = (byte[])keyHash.Clone();
Buffer.BlockCopy(new Guid("00000000-0000-0000-0000-000000000000").ToByteArray(), 0, this.header, 0, 16);
Buffer.BlockCopy(keyHash, 0, this.header, 16, keyHash.Length);
}
internal ProtectedBytes(byte[] plaintext)
{
this.ciphertext = new byte[(plaintext.Length + 0xF) & ~0xF];
Buffer.BlockCopy(plaintext, 0, ciphertext, 0, plaintext.Length);
ProtectedMemory.Protect(ciphertext, MemoryProtectionScope.SameProcess);
this.plaintextLength = plaintext.Length;
}发布于 2022-09-07 16:33:50
沙-1仍然在最新的FIPS-140-2附件A中获得批准。然而,对于某些用途,NIST SP 800-131 A REV.2不推荐使用SHA-1。
我会调查移动到SHA-2或更高的任何可能的未来打样(并符合较宽松的标准)。
发布于 2022-09-07 21:36:33
你的代码有问题。
最后,您清除了keyData,这很好。这确保内存转储不会包含加密密钥。
ProtectedBytes。没有源代码,就很难知道它在做什么。但是,如果可以从这个对象中提取密钥,那么这就是一个问题。ServiceEncryptionKey的目的还不清楚。如果您使用哈希进行加密,那么有效的加密密钥将保留在内存中,因此可以通过内存转储来检索。这就是为什么在最后清除keyData不能使代码更加安全的原因。https://security.stackexchange.com/questions/264656
复制相似问题