在「AESCryptoServiceProvider」中,生成內部使用的()方法CryptGenRandom()
的advapi32.dll
。 GenerateIV的
方法認定中():
public override void GenerateIV() {
Contract.Ensures(IVValue != null && IVValue.Length == BlockSizeValue/8);
Contract.Assert(m_cspHandle != null);
Contract.Assert(BlockSizeValue % 8 == 0);
byte[] iv = new byte[BlockSizeValue/8];
if (!CapiNative.UnsafeNativeMethods.CryptGenRandom(m_cspHandle, iv.Length, iv)) {
throw new CryptographicException(Marshal.GetLastWin32Error());
}
IVValue = iv;
}
CryptGenRandom的簽名():
/// <summary>
/// Fill a buffer with cryptographically random bytes
/// </summary>
[DllImport("advapi32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptGenRandom(SafeCspHandle hProv,
int dwLen,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbBuffer);
http://stackoverflow.com/questions/8041451/good-aes-initialization-vector-練習 – vikky 2015-02-12 08:58:14
已經通過該線程。不管怎樣,謝謝。它說在密碼文本和混淆之前預先安排。 也檢查NIST的標準。 http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf 檢查此以及 http://security.stackexchange.com/questions/42642/should-aes-always -give-the-same-output – 2015-02-12 09:26:52