首先,我使用的 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 &”
最佳答案
在documentation , SymmetricKey
(这只是 OctetString
的类型定义)可以采用字节数组和长度作为构造函数。或者,您可以将 key 编码为十六进制字符串。如果您已经拥有 std::vector<byte>
的 key ,那么这就足够了:
std::vector<byte> keybytes;
// ...fill the vector...
SymmetricKey key( keybytes.data(), keybytes.size() );
Botan 的更高版本定义了另一个构造函数 OctetString (const std::vector<byte> &in)
.
关于c++ - 无法创建 SymmetricKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31012824/