1

首先我使用的 Botan 版本是 Botan-1.10.9 我正在用 Visual C++ 编写一个托管包装器

按照这个例子,我试图从一个字符串的哈希中创建一个 SymmetricKey,这样我就可以将它传递给 FPE 模块的 fe1_encrypt 方法

fe1_encrypt 的签名是

BigInt FPE::fe1_encrypt(const BigInt &n, const BigInt &X, const SymmetricKey &key, const std::vector<byte> &tweak)

我希望我传递给 key 参数的值是明文的哈希值(不可能解密)所以我真的不在乎它是一个 SymmetricKey,只需要那种类型,因为该方法需要它作为参数。

但是在他们的示例中,他们已经将 SymmetricKey 传递给了返回 std:vector 的哈希方法

但是,没有采用这种类型的 SymmetricKey 构造函数。

有人有想法么?

编辑:我试过这个没有运气

std::vector<byte> re = SHA_1(plaintextAsString);
Botan::OctetString key(re, re.size());

错误

错误 15 错误 C2664: 'Botan::OctetString::OctetString(Botan::RandomNumberGenerator &,size_t)' : 无法将参数 1 从 'std::vector<_Ty>' 转换为 'Botan::RandomNumberGenerator &'

4

1 回答 1

1

文档中,SymmetricKey(这只是一个 typedef OctetString)可以将字节数组和长度作为构造函数。或者,您可以将密钥编码为十六进制字符串。如果您已经拥有密钥 as std::vector<byte>,那么这就足够了:

std::vector<byte> keybytes;
// ...fill the vector...

SymmetricKey key( keybytes.data(), keybytes.size() );

Botan 的更高版本定义了另一个构造函数OctetString (const std::vector<byte> &in)

于 2015-06-23T20:48:54.023 回答