【Dotnet 工具箱】WPF UI - 现代化设计的开源 WPF 框架

发布时间 2023-04-19 09:10:17作者: Dotnet工具箱

1.WPF UI - 现代化设计的开源 WPF 框架

WPF UI 是一个基于 C# 开发的, 拥有 4k star 的开源 UI 框架。WPF UI 在 WPF 的基础上,提供了更多的现代化,流利的,直观的设计和组件。重要的是,WPF UI 完全免费!

如果你对 WPF 比较熟悉,那么可以很快的上手这个 UI 框架,并集成中项目中去。WPF UI 提供了完善的使用文档,对新手非常友好。

截图

如何使用

  1. 使用 Visual Studio 中的 Nuget 包管理器,安装 WPF-UI

  2. 更新 App.xaml 文件,如下

    <Application 
      xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
      <Application.Resources>
        <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
            <ui:ThemesDictionary Theme="Dark" />
            <ui:ControlsDictionary />
          </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
      </Application.Resources>
    </Application>
    
  3. 试试 WPF-UI 的按钮, 尽情使用吧!

    <ui:UiWindow
      ...
      xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
      <Grid>
        <ui:Button
          Content="Hello World"
          Icon="Fluent24"/>
      </Grid>
    </ui:UiWindow>
    

项目地址: https://wpfui.lepo.co/

2.开源力作!使用 Blazor 和 C# 构建 K8s Dashboard

blazor-k8s

blazor-k8s 是一个开源项目,它使用了 blazor 和 C# 构建了 k8s dashboard。允许用户在界面上直接操作 k8s,进行资源管理。

部署

1 k8s部署体验

一键安装

kubectl apply -f https://raw.githubusercontent.com/weibaohui/blazork8s/main/deploy/deployment.yaml

访问

默认使用了nodePort开放,请访问31999端口 http://NodePortIP:31999

docker 体验
启动服务器

docker run -d --name blazork8s  -v ~/.kube/:/root/.kube/ -p 4001:443 -p 4000:80 ghcr.io/weibaohui/blazork8s:latest

界面预览

项目地址:https://github.com/weibaohui/blazork8s

3. Dotnet 加解密算法库

CryptoNet

CryptoNet 是一个简单、快速且轻量级的非对称和对称加密 NuGet 库,支持跨平台 Windows、Linux。不依赖其他库, 100% C# 实现。

CryptoNet 可以通过两种方式使用:

  • 对称方式
  • 非对称方式

对称方式

您使用相同的密钥进行加密和解密。

非对称方式

通过非对称方式,CryptoNet 可以使用自己生成的 RSA 密钥对(私钥/公钥)来加密和解密内容。

您可以将私钥存储在一台或多台机器上。公钥可以轻松分发给所有客户端。

使用示例

1.使用对称密钥加密和解密内容

在下面示例中,CryptoNetAes 生成随机的密钥和 iv。

ICryptoNet cryptoNet = new CryptoNetAes();
var key = cryptoNet.ExportKey();

ICryptoNet encryptClient = new CryptoNetAes(key);
var encrypt = encryptClient.EncryptFromString(ConfidentialDummyData);

ICryptoNet decryptClient = new CryptoNetAes(key);
var decrypt = decryptClient.DecryptToString(encrypt);

Debug.Assert(ConfidentialDummyData == decrypt);

2.使用导出和导入, 自己生成的对称密钥,来加密和解密内容

ICryptoNet cryptoNet = new CryptoNetAes();
var file = new FileInfo(SymmetricKeyFile);
cryptoNet.ExportKeyAndSave(file);

Debug.Assert(File.Exists(file.FullName));

var encrypt = cryptoNet.EncryptFromString(ConfidentialDummyData);
        
ICryptoNet cryptoNetKeyImport = new CryptoNetAes(file);
var decrypt = cryptoNetKeyImport.DecryptToString(encrypt);

Debug.Assert(ConfidentialDummyData == decrypt);

3. 生成非对称 Rsa 密钥对,导出私钥和公钥,使用公钥加密和使用私钥解密

ICryptoNet cryptoNet = new CryptoNetRsa();

cryptoNet.ExportKeyAndSave(new FileInfo(PrivateKeyFile), true);
cryptoNet.ExportKeyAndSave(new FileInfo(PublicKeyFile), false);

Debug.Assert(File.Exists(new FileInfo(PrivateKeyFile).FullName));
Debug.Assert(File.Exists(new FileInfo(PublicKeyFile).FullName));

ICryptoNet cryptoNetPubKey = new CryptoNetRsa(new FileInfo(PublicKeyFile));
var encrypt = cryptoNetPubKey.EncryptFromString(ConfidentialDummyData);

ICryptoNet cryptoNetPriKey = new CryptoNetRsa(new FileInfo(PrivateKeyFile));
var decrypt = cryptoNetPriKey.DecryptToString(encrypt);

Debug.Assert(ConfidentialDummyData == decrypt);

4. 使用 X509 证书用公钥加密,然后用私钥解密

X509Certificate2? certificate = CryptoNetUtils.GetCertificateFromStore("CN=Maytham");

ICryptoNet cryptoNetWithPublicKey = new CryptoNetRsa(certificate, KeyType.PublicKey);
var encryptWithPublicKey = cryptoNetWithPublicKey.EncryptFromString(ConfidentialDummyData);

ICryptoNet cryptoNetWithPrivateKey = new CryptoNetRsa(certificate, KeyType.PrivateKey);
var decryptWithPrivateKey = cryptoNetWithPrivateKey.DecryptToString(encryptWithPublicKey);

Debug.Assert(ConfidentialDummyData == decryptWithPrivateKey);

项目地址: https://github.com/maythamfahmi/CryptoNet