C++如何制作带有boost的简单sha256发生器?

发布于 2024-11-26 04:02:37 字数 103 浏览 3 评论 0原文

我需要一个简单的 sha256 生成器类字符串。我不想为此构建大型库,例如 openSSL 或 Cripto++ - 我想要的只是将字符串转换为 sha256。如何创建这样的类或从哪里获取它?

I need a simple string to sha256 generator class. I do not want to build big libraries for that like openSSL or Cripto++ - all I want is to turn strings into sha256. How to create such class or where to get it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

匿名。 2024-12-03 04:02:37

正如其他人所说,我的印象是 SHA256 下的散列不足以简单地将自己实现为更大编码项目的子集。如果您查看SHA-2 的维基百科页面,您会注意到一些漂亮的内容密集的数学。如果您想要实际的加密摘要(数学理论本身),可以找到这里。如果您像大多数程序员一样,重点不在于安全性,那么您可能只想使用其他人经过测试和尝试的实现。您可以在此处找到一些。让我知道这是否有帮助。抱歉,我无法用直接代码或类似性质的东西来回答您的问题。

Like others have said, I was under the impression that hashing under SHA256 is not trivial enough to simply implement yourself as a subset of a bigger coding project. If you take a look at the wikipedia page for SHA-2, you will notice some pretty intense math. If you would like the actual encryption abstract (the math theory itself), it can be found here. If you're like most programmers whose emphasis is not in security, then you will probably want to simply use someone else's tested and tried implementation. You can find a good few here. Let me know if this helped. Sorry I couldn't answer your question with straight code or something of that nature.

北方的韩爷 2024-12-03 04:02:37

您可以直接在 RFC 6234 的第 8 节中找到 C 源代码。请务必检查勘误表

You find C source code directly in the section 8 of RFC 6234. Make sure you check the errata also.

家住魔仙堡 2024-12-03 04:02:37

你想要这个吗?

static void
sha2_round(const unsigned char *data, sph_u32 r[8])
{
    int i;
    sph_u32 a, b, c, d, e, f, g, h;
    sph_u32 w[64];

    for (i = 0; i < 16; i ++)
        w[i] = sph_dec32be_aligned(data + (4 * i));
    for (i = 16; i < 64; i ++) {
        w[i] = SPH_T32(SSG2_1(w[i - 2]) + w[i - 7]
            + SSG2_0(w[i - 15]) + w[i - 16]);

转到 http://www.saphir2.com/sphlib/
并下载它。它受 GPL 约束。 请注意查看 sha2.c

,它没有很多文档。它是为那些已经知道自己在做什么的人而设置的。

you want this?

static void
sha2_round(const unsigned char *data, sph_u32 r[8])
{
    int i;
    sph_u32 a, b, c, d, e, f, g, h;
    sph_u32 w[64];

    for (i = 0; i < 16; i ++)
        w[i] = sph_dec32be_aligned(data + (4 * i));
    for (i = 16; i < 64; i ++) {
        w[i] = SPH_T32(SSG2_1(w[i - 2]) + w[i - 7]
            + SSG2_0(w[i - 15]) + w[i - 16]);

go to http://www.saphir2.com/sphlib/
and download it. it's under the GPL. look in sha2.c

beware, it doesn't have a lot of documentation. it's set up for people who already know what they're doing.

两仪 2024-12-03 04:02:37

GNU coreutils 有一个非常简单的源代码。
只需下载 coreutils,他们甚至有一个可以构建的测试套件,并且源代码充满了注释和文档。

GNU coreutils has a very simple source code.
just download coreutils, they even have a test suite you can build, and the source code is full of comments and docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文