public Key GeneratepPotectKey(string location) { if (!_fileHandler.DirectoryExists(location)) { _fileHandler.CreateDirectory(location); } string KeyFileName = Guid.NewGuid().ToString(); Key keyFile = new Key(); RSACryptoServiceProvider Algorithm = new RSACryptoServiceProvider(_keySize); string CompleteKey = Algorithm.ToXmlString(true); byte[] KeyBytes = Encoding.UTF8.GetBytes(CompleteKey); KeyBytes = ProtectedData.Protect(KeyBytes, null, DataProtectionScope.LocalMachine); keyFile.PublicKey = Algorithm.ToXmlString(false); keyFile.FileName = $"{KeyFileName}.config"; _fileHandler.Save(location, keyFile, KeyBytes); return(keyFile); }