public void Protect(ISiteSettings site)
{
if (site == null) { throw new ArgumentNullException("you must pass in an implementation of ISiteSettings"); }
if (site.IsDataProtected) { return; }
if (dataProtector == null) { return; }
var countOfProtectedItems = 0;
if (site.FacebookAppSecret.Length > 0)
{
try
{
site.FacebookAppSecret = dataProtector.PersistentProtect(site.FacebookAppSecret);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.GoogleClientSecret.Length > 0)
{
try
{
site.GoogleClientSecret = dataProtector.PersistentProtect(site.GoogleClientSecret);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.MicrosoftClientSecret.Length > 0)
{
try
{
site.MicrosoftClientSecret = dataProtector.PersistentProtect(site.MicrosoftClientSecret);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.TwitterConsumerSecret.Length > 0)
{
try
{
site.TwitterConsumerSecret = dataProtector.PersistentProtect(site.TwitterConsumerSecret);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.SmtpPassword.Length > 0)
{
try
{
site.SmtpPassword = dataProtector.PersistentProtect(site.SmtpPassword);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.OidConnectAppSecret.Length > 0)
{
try
{
site.OidConnectAppSecret = dataProtector.PersistentProtect(site.OidConnectAppSecret);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.DkimPrivateKey.Length > 0)
{
try
{
site.DkimPrivateKey = dataProtector.PersistentProtect(site.DkimPrivateKey);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
if (site.SmsSecureToken.Length > 0)
{
try
{
site.SmsSecureToken = dataProtector.PersistentProtect(site.SmsSecureToken);
countOfProtectedItems += 1;
}
catch (System.Security.Cryptography.CryptographicException ex)
{
log.LogError("data protection error", ex);
}
}
site.IsDataProtected = countOfProtectedItems > 0;
}