public LocalDataProtectionProviderBase( IProtectedData protectedData, IDataProtectionProvider dataProtectionProvider) { this.protectedData = protectedData; this.dataProtectionProvider = dataProtectionProvider; if (OperatingSystem2.IsWindows) { if (OperatingSystem2.IsWindows10AtLeast) { defaultELocalDataProtectionType = LocalDataProtectionType.Win10WithAesCFB; } else { defaultELocalDataProtectionType = LocalDataProtectionType.ProtectedDataWithAesCFB; } } else { defaultELocalDataProtectionType = LocalDataProtectionType.AesCFB; } _aes = new Lazy <Aes>(() => { (var key, var iv) = MachineSecretKey; // https://github.com/dotnet/runtime/issues/42214#issuecomment-698495584 // AES CFB in Windows 7 catch Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unknown error (0xc10000bb) // AES CFB in Android catch CryptographicException: Bad PKCS7 padding. Invalid length var mode = OperatingSystem2.IsAndroid ? CipherMode.CBC : CipherMode.CFB; var r = AESUtils.Create(key, iv, mode, PaddingMode.PKCS7); return(r); }); }
public LocalDataProtectionProviderBase( IProtectedData protectedData, IDataProtectionProvider dataProtectionProvider) { this.protectedData = protectedData; this.dataProtectionProvider = dataProtectionProvider; switch (DI.Platform) { case Platform.Windows: if (Environment.OSVersion.Version.Major >= 10) { defaultELocalDataProtectionType = LocalDataProtectionType.Win10WithAesOFB; } else { defaultELocalDataProtectionType = LocalDataProtectionType.ProtectedDataWithAesOFB; } break; case Platform.Linux: defaultELocalDataProtectionType = LocalDataProtectionType.AesOFB; break; default: defaultELocalDataProtectionType = LocalDataProtectionType.None; break; } _aes = new Lazy <Aes>(() => { (byte[] key, byte[] iv) = MachineSecretKey; var r = AESUtils.Create(key, iv, CipherMode.CFB, PaddingMode.PKCS7); return(r); }); }
public LocalDataProtectionProviderBase( IProtectedData protectedData, IDataProtectionProvider dataProtectionProvider) { this.protectedData = protectedData; this.dataProtectionProvider = dataProtectionProvider; switch (DI.Platform) { case Platform.Windows: if (Environment.OSVersion.Version.Major >= 10) { defaultELocalDataProtectionType = LocalDataProtectionType.Win10WithAesOFB; } else { defaultELocalDataProtectionType = LocalDataProtectionType.ProtectedDataWithAesOFB; } break; case Platform.Linux: defaultELocalDataProtectionType = LocalDataProtectionType.AesOFB; break; default: defaultELocalDataProtectionType = LocalDataProtectionType.None; break; } _aes = new Lazy <Aes>(() => { (byte[] key, byte[] iv) = MachineSecretKey; // https://github.com/dotnet/runtime/issues/42214#issuecomment-698495584 // AES CFB in Windows 7 catch Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unknown error (0xc10000bb) var r = AESUtils.Create(key, iv, CipherMode.CFB, PaddingMode.PKCS7); return(r); }); }
public LocalDataProtectionProvider(IProtectedData protectedData, IDataProtectionProvider dataProtectionProvider) : base(protectedData, dataProtectionProvider) { MachineSecretKey = GetMachineSecretKey(); }