Summary:
, . MachineKey.Protect IV , .
Detail
Microsoft , .
: MachineKey
AspNetCryptoServiceProvider
AspNetCryptoServiceProvider.GetCryptoService NetFXCryptoService, :
public byte[] Protect(byte[] clearData) {
checked {
using (SymmetricAlgorithm encryptionAlgorithm = _cryptoAlgorithmFactory.GetEncryptionAlgorithm()) {
encryptionAlgorithm.Key = _encryptionKey.GetKeyMaterial();
if (_predictableIV) {
encryptionAlgorithm.IV = CryptoUtil.CreatePredictableIV(clearData, encryptionAlgorithm.BlockSize);
}
else {
encryptionAlgorithm.GenerateIV();
}
byte[] iv = encryptionAlgorithm.IV;
using (MemoryStream memStream = new MemoryStream()) {
memStream.Write(iv, 0, iv.Length);
using (ICryptoTransform encryptor = encryptionAlgorithm.CreateEncryptor()) {
using (CryptoStream cryptoStream = new CryptoStream(memStream, encryptor, CryptoStreamMode.Write)) {
cryptoStream.Write(clearData, 0, clearData.Length);
cryptoStream.FlushFinalBlock();
using (KeyedHashAlgorithm signingAlgorithm = _cryptoAlgorithmFactory.GetValidationAlgorithm()) {
signingAlgorithm.Key = _validationKey.GetKeyMaterial();
byte[] signature = signingAlgorithm.ComputeHash(memStream.GetBuffer(), 0, (int)memStream.Length);
memStream.Write(signature, 0, signature.Length);
byte[] protectedData = memStream.ToArray();
return protectedData;
}
}
}
}
}
}
}
, _predictableIV - false.
IV, , , .
IV , Unprotect .