E不小心

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  38 随笔 :: 0 文章 :: 77 评论 :: 18万 阅读

2022年8月10日

Zig 中做Md5 和 Sha1 之类的Hash 非常简单的,现在支持Hash 算法有,blanke2Blanke3GimliMd5Sha1sha2sha3,还有一个 组合 composition

Md5

pub fn md5() void {
    const Md5 = std.crypto.hash.Md5;

    var out: [Md5.digest_length]u8 = undefined;

    const input = "1234567890";

    Md5.hash(input, &out, .{});

    std.debug.print("\"{s}\" md5 code is {s}\n", .{ input, std.fmt.fmtSliceHexLower(out[0..]) });
}

"1234567890" md5 code is e807f1fcf82d132f9bb018ca6738a19f

Sha1

pub fn sha1() void {
    const Sha1 = std.crypto.hash.Sha1;

    var out: [Sha1.digest_length]u8 = undefined;

    const input = "1234567890";

    Sha1.hash(input, &out, .{});

    std.debug.print("\"{s}\" sha1 code is {s}\n", .{ input, std.fmt.fmtSliceHexLower(out[0..]) });
}

"1234567890" sha1 code is 01b307acba4f54f55aafc33bb06bbbf6ca803e9a

Composition

组合可以把两相同 api 的 hash 进行组合计算,默认提供了 Sha256oSha256、Sha384oSha384、Sha512oSha512。

我们可以试试来组合 Md5 和 Sha1,

pub fn composition() void {
    const Md5oSha1 = std.crypto.hash.composition.Composition(std.crypto.hash.Md5, std.crypto.hash.Sha1);

    var out: [Md5oSha1.digest_length]u8 = undefined;

    const input = "1234567890";

    Md5oSha1.hash(input, &out, .{});

    std.debug.print("\"{s}\" Md5oSha1 code is {s}\n", .{ input, std.fmt.fmtSliceHexLower(out[0..]) });
}

"1234567890" Md5oSha1 code is 1e0a1082ef56d0586330c3c46c5d46d1

这个组件的操作会先计算 Sha1 ,得到的结果再进行 Md5 计算。就相当于下面的代码:

pub fn md5OSha1() void {
    const Md5 = std.crypto.hash.Md5;
    const Sha1 = std.crypto.hash.Sha1;

    const input = "1234567890";

    var out: [Sha1.digest_length]u8 = undefined;
    var dest: [Md5.digest_length]u8 = undefined;

    Sha1.hash(input, &out, .{});

    Md5.hash(&out, &dest, .{});

    std.debug.print("\"{s}\" same Md5oSha1 code is {s}\n", .{ input, std.fmt.fmtSliceHexLower(dest[0..]) });
}
posted @ 2022-08-10 20:55 E不小心 阅读(306) 评论(0) 推荐(0) 编辑

2022年5月7日

摘要: 【Electron】使用 build-tools 在 Windows 中编译 electron 提前准备 预留好磁盘空间 Git 缓存目录:%UserProfile%/.git_cache ,大概有 16G。 electron_build_tools 目录:%UserProfile%/.electr 阅读全文
posted @ 2022-05-07 11:29 E不小心 阅读(1317) 评论(0) 推荐(0) 编辑

2022年4月29日

摘要: 【Electron】在 WSL2 中 打包 electron Linux 版本应用及运行 打包 electron 应用 安装 WSL 我使用的是 Ubuntu 20.04.4 LTS 的版本。 安装 WSL 文档地址:https://docs.microsoft.com/zh-cn/windows/ 阅读全文
posted @ 2022-04-29 11:36 E不小心 阅读(1875) 评论(0) 推荐(0) 编辑

2022年4月11日

摘要: 【Electron】Electron Icon 图标说明、及常见问题 其实各种打包模块都有相关的文档说明,相关链接如下: electron-builder:https://www.electron.build/icons.html electron-packager: https://electro 阅读全文
posted @ 2022-04-11 17:32 E不小心 阅读(6205) 评论(0) 推荐(0) 编辑

2022年4月1日

摘要: 一个各平台调用 C/C++ 源码的例子,如何共享代码,配置相关的编译 官方的例子:https://docs.flutter.dev/development/platform-integration/c-interop 源码地址:https://github.com/gaoshang212/flutt 阅读全文
posted @ 2022-04-01 18:46 E不小心 阅读(4521) 评论(2) 推荐(1) 编辑

2022年1月25日

摘要: 问题 electron-builder使用nsis打包,安装时不会设置URL Protocol。 解决方法 自定义nsis 脚本 electron-builder 可以自定义打包脚本 https://www.electron.build/configuration/nsis#custom-nsis- 阅读全文
posted @ 2022-01-25 16:55 E不小心 阅读(601) 评论(0) 推荐(0) 编辑

2022年1月17日

摘要: windows上 使用 check-disk-space 获取磁盘空间碰到两个问题 在用户端碰到两个问题 无法找到wmic命令。 提示"不是内部或外部命令,也不是可运行的程序"等 可以在执行前配置PATH中包含 %SystemRoot%/System32/wbem 或 %windir%/System 阅读全文
posted @ 2022-01-17 11:03 E不小心 阅读(669) 评论(0) 推荐(0) 编辑

2021年11月26日

摘要: 数字范围参数 有的时候我们想定义一个参数的数字范围,如果范围比较小点好,比如1到5。 type Range = 1 | 2 | 3 | 4 | 5 ; 但如果数字范围很大,比如 1到100,或是1到1000,那就要写死了。 支持现状 Github上有人提了相关的建议,但还处于Open状态 https 阅读全文
posted @ 2021-11-26 17:53 E不小心 阅读(1408) 评论(0) 推荐(0) 编辑

2021年11月19日

摘要: 原因 最近碰有人问怎么查看主进程日志,简单写一下windows、mac如何启动了。主要是面向新手、老手自动滑过吧 启动方式 Windows 启动命令行 Powershell 或 CMD 进入到程序的安装目录。以XMind Zen 为例: #Powershell PS C:\Program Files 阅读全文
posted @ 2021-11-19 16:53 E不小心 阅读(846) 评论(0) 推荐(0) 编辑

2021年11月2日

摘要: 需求,想要的功能 默认 Program Files 或 Program Files(x86) 可以选择安装目录 安装后自动运行程序 electorn-builder nsis 配置,如下: { oneClick: false, perMachine: true, allowElevation: tr 阅读全文
posted @ 2021-11-02 11:52 E不小心 阅读(2439) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示