我想使用一些加密操作(主要是整合检查hashsums).但是我在查找执行此类操作的文档时遇到问题:
bool read(std::istream &in) {
hasher hv(in);
// Do some operations on hv as if it was std::istream
hash_type h = hv.finish ();
hash_type h2 = read_hash(in);
return h == h2;
}
Run Code Online (Sandbox Code Playgroud)
PS.它可能是不同的库,只要它a)是GPL-3兼容的b)适用于GNU/Linux
PPS.我并不坚持使用crypto ++,但是我想要与其他C++库具有类似IOStream的行为,以实现互操作性.
我在Wei Dai的Crypto ++应用程序中创建了一个ECDSA密钥对(secp128r1).签名和验证按预期工作.我没有将消息本身添加到签名中以最小化签名长度(正好是32字节).
但是,当我使用openssl创建签名时:
$ cat test.txt | openssl dgst -ecdsa-with-SHA1 -sign sample.key -keyform DER > act.bin
Run Code Online (Sandbox Code Playgroud)
OpenSSL显然将消息本身放到签名上,从而产生更大的签名(例如39字节).如果我设置,我可以使用Crypto ++验证签名CryptoPP::SignatureVerificationFilter::PUT_MESSAGE.
我是否可以告诉OpenSSL签署一条消息而不将消息放入签名,以便生成的签名完全是32字节?
我有十六进制的字符串,我需要转换为const byte*.我正在使用Crypto ++进行散列,它需要密钥才能使用const byte*任何方法我可以将十六进制字符串转换为const byte*使用任何Crypto ++库,或者我是否需要自己编写?
我想将myVar转换CryptoPP:Integer为char*或转换为String:代码如下:
CryptoPP::Integer myVar = pubKey.ApplyFunction(m);
std::cout << "result: " << std::hex << myVar<< std::endl;
Run Code Online (Sandbox Code Playgroud)
我一直在互联网上寻找转换CryptoPP:Integer,char*但我找不到运气.所以,无论是转换CryptoPP:Integer到所有人都是一个真正的问题char*,要么我CryptoPP:Integer在C++中都不太了解类型.
有谁可以帮助我吗?
是否可以使用 crypto++ 库来解码字节数组中的任意 ASN1 数据(其中有几个序列和整数)。ash.h 包含所有以 BufferedTransformation 作为输入的方法,但该类是不同密码和哈希的接口,这似乎与我的简单情况根本无关。我还在 cryptlib.h 中找到了 ASN1Object,但它是另一个接口,我还没有找到任何实现类。
我是否认为这对我自己来说太复杂了,或者解码任意 ASN1 数据实际上很困难?
我实际上在 Swift/objective-c iOS 应用程序中使用它,所以如果有人使用其他工具有一个简单的解决方案,请告诉我。
编辑:添加数据的示例结构
SEQUENCE
SEQUENCE
INTEGER
INTEGER
SEQUENCE
INTEGER
INTEGER
Run Code Online (Sandbox Code Playgroud)
总有一个父序列包含 1 到 n 个序列,每个序列包含 2 个整数(elgamal 加密对 (g^r, mh^r))。
我cryptopp在Ubuntu 64bit机器上使用.我需要编译32位的库,但我不知道如何.
我应该在GNU Makefile中做一些更改,还是在调用时使用可选参数make?
如果我想使用 Crypto++ 库加密数据并使用小于 32 字节的用户定义密码怎么办?
现在我有以下代码:
byte passwordBytes[AES::MAX_KEYLENGTH];
byte ivBytes[AES::BLOCKSIZE];
std::string textToEncrypt("encryptMe");
std::string aesKey("passwordFromUser");
std::string ivText("Iv16BytesOfText...");
memset(passwordBytes, 0, sizeof(passwordBytes)); //fill with zeroes first
memcpy(passwordBytes, aesKey.data(), aesKey.size()); //fill with key data
memcpy(ivBytes, ivText.data(), CryptoPP::AES::BLOCKSIZE); //fill iv bytes
CTR_Mode<AES>::Encryption encryption;
encryption.SetKeyWithIV(passwordBytes, sizeof(passwordBytes), ivBytes);
StringSource encryptor(textToEncrypt, true,
new StreamTransformationFilter(encryption,
new StringSink(verschluesselterText)
,StreamTransformationFilter::NO_PADDING
)
);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,aesKey小于 32 字节。
要将完整的 32 字节应用于加密函数,我只需用零填充未使用的空间,但这对我来说似乎不是最好的解决方案。
我是否遗漏了有关创建 AES 密钥的信息?使用用户定义的密码?
我的第二个问题,如果用户选择的密码长于 32 字节怎么办?就我而言,密码会被截断,这对我来说听起来不太正确。
感谢您的帮助!
是否有任何等效的用于加密原语的开源 ANSI-C 库。我知道 C++ 的 Crypto++,但找不到 C 的任何东西
我主要需要 SHA-1、SHA-2、AES、RSA
如标题所示,我正在寻找cryptopp 库中此声明之间的差异:
CBC_Mode<AES>::Decryption
cbcDecryption.SetKeyWithIV(key, AES::DEFAULT_KEYLENGTH, iv);
Run Code Online (Sandbox Code Playgroud)
和这个:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
Run Code Online (Sandbox Code Playgroud)
此外,我不明白为什么这样:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
StreamTransformationFilter stfDecryptor(
cbcDecryption,
new StringSink( recoveredtext )
);
stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
stfDecryptor.MessageEnd();
Run Code Online (Sandbox Code Playgroud)
使用模板模式时一切正常我在运行时遇到此错误:
AES128CBC: /usr/local/include/cryptopp/misc.h:304: void CryptoPP::memcpy_s(void*, size_t, const void*, size_t): Assertion `dest != __null' failed.
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)
不应该是一样的吗?
我看过这个,但我不太明白其中的区别,在网上搜索我找不到问题的答案。
我想将 Crypto++ 密钥保存到std::vector<uint8_t>. 不幸的是,只有CryptoPP::StringSink, that 需要std::string参考,但没有CryptoPP::VectorSink那个会参考std::vector.
以下代码工作正常
std::string spki;
CryptoPP::StringSink ss(spki);
CryptoPP::RSA::PublicKey publicKey(...);
publicKey.Save(ss);
Run Code Online (Sandbox Code Playgroud)
但我想要这个
std::vector<uint8_t> spki;
CryptoPP::VectorSink vs(spki);
CryptoPP::RSA::PublicKey publicKey(...);
publicKey.Save(vs);
Run Code Online (Sandbox Code Playgroud)
问题
VectorSink不能仅通过使用 typedef 来创建,因为 traits_type::char_typeinside StringSinkTemplate:
using CryptoPP::StringSinkTemplate;
typedef StringSinkTemplate< std::vector<byte> > VectorSink;
In file included from cryptopp-test.cpp:65:
In file included from /usr/local/include/cryptopp/files.h:5:
/usr/local/include/cryptopp/filters.h:590:22: error: no member named
'traits_type' in 'std::vector<unsigned char, std::allocator<unsigned char>
>'
typedef typename T::traits_type::char_type char_type;
~~~^
cryptopp-test.cpp:243:20: note: in instantiation of …Run Code Online (Sandbox Code Playgroud) crypto++ ×10
c++ ×9
cryptography ×5
aes ×1
asn.1 ×1
c ×1
cryptoapi ×1
ecdsa ×1
encoding ×1
encryption ×1
openssl ×1
stdvector ×1
visual-c++ ×1