- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在使用 CryptoPP 时遇到问题。我正在使用 AES,并且想通过将其编码为 base64 来表示二进制密文。
我的问题是我在运行以下代码时随机出现断言错误:
std::string encoded;
// ciphertext is of type std::string from AES
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
具体的断言错误是:
Assertion failed: m_allocated, file include\cryptopp\secblock.h, line 197
由于这种“随机”行为,它让我相信问题出在密文的内容中。
我的问题是:我这样做的方式是否正确?我被难住了一段时间,并且一直在研究但没有成功。我能找到的最接近的是:http://www.mail-archive.com/cryptopp-users@googlegroups.com/msg06053.html
我的完整实现是:
std::string key = "key";
std::string in = "This is a secret message.";
CryptoPP::SHA1 sha;
byte digest[CryptoPP::SHA1::DIGESTSIZE];
sha.CalculateDigest(digest, reinterpret_cast<const byte *>(key.c_str()), key.length());
byte iv[CryptoPP::AES::BLOCKSIZE];
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE);
CryptoPP::AES::Encryption encrypt(reinterpret_cast<const byte *>(digest), CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbc_encrypt(encrypt, iv);
std::string ciphertext;
CryptoPP::StreamTransformationFilter encryptor(cbc_encrypt,
new CryptoPP::StringSink(ciphertext));
encryptor.Put(reinterpret_cast<const unsigned char *>(in.c_str()), in.length() + 1);
encryptor.MessageEnd();
std::string encoded;
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
最佳答案
My question is: Am I doing this the correct way?
是的,代码没问题(digest.erase();
除外)。
I've been stumped for a while, and have been researching a bit without success.
在内存检查器下运行它。 Valgrind 或 Clang Asan(地址 sanitizer )。
The closest thing I can find is: http://www.mail-archive.com/cryptopp-users@googlegroups.com/msg06053.html
我过去也遇到过这种说法。我不记得是 iOS 还是 Linux。我认为是带有特定版本 GCC(可能是 4.4 或 4.5)的 Linux。
My problem is that I am randomly getting assertion errors when running the following code:
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
将上面的改成这样:
CryptoPP::StringSource ss(ciphertext, true,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
GCC 的一个版本在匿名声明方面存在问题。它会过早开始运行对象析构函数。
关于c++ - 在二进制数据(密文)上使用 CryptoPP::Base64Encoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8015495/
我的 SEAL v2.3.1 中有这些 SEAL 设置: seal::EncryptionParameters parms; parms.set_poly_modulus("1x^2048 + 1")
我有一些使用 Perl 的 Crypt::CBC 加密的密文我希望在其他地方解密的模块。 密文是使用 Crypt::CBC 的“简单”版本生成的。构造函数,即: use Crypt::CBC; $ci
我在使用 CryptoPP 时遇到问题。我正在使用 AES,并且想通过将其编码为 base64 来表示二进制密文。 我的问题是我在运行以下代码时随机出现断言错误: std::string encode
据我所知,RSA 加密的输出将等于 key 模数的长度(在本例中为 128 字节)。我的 RSA 加密代码是: public byte [] RSAEncrypter () throws Except
情况: 我正在尝试从我的谷歌云存储桶中下载和解密一些数据。 对于加密和解密,我使用: https://cloud.google.com/kms/docs/quickstart#decrypt_data
我使用此 openssl 命令创建了一条加密消息: openssl enc -aes-256-cbc -salt -in plaintext.txt -out cipher.enc 我尝试过 Cryp
我正在尝试将 AES 加密的 Java 代码复制到 Golang 中。但是我在 golang 中没有得到相同的输出 我试过下面的代码: Java 代码: package EncryptionTest;
我通过 java 、 BouncyCaSTLe Provider 实现这个使用 block 模式 = ECB 和填充模式 = PKCS7Padding 我注意到,如果我加密32字节长度的数据(例如61
我看过类似的主题,但我找不到与我正在努力实现的目标完全相符的解决方案。 我有一个密文,需要根据每个字母在文本中出现的频率进行简单的字母替换。我已经有一个规范化文本的功能(小写,没有非字母字符,没有,计
我是一名优秀的程序员,十分优秀!