是否有可能存储在一个源例如RSA公钥/私钥byte[]或string或任何其他container与使用该密钥用于加密/解密?
文件中的解码函数如下所示:
void Decode(const string& filename, BufferedTransformation& bt)
{
// http://www.cryptopp.com/docs/ref/class_file_source.html
FileSource file(filename.c_str(), true /*pumpAll*/);
file.TransferTo(bt);
bt.MessageEnd();
}
Run Code Online (Sandbox Code Playgroud)
从文件加载密钥不是我想要的.
我知道它必须是可能的,因为我可以创建密钥AutoSeededRandomPool.
我只是不知道如何使用现有的.
也许我在文档中忽略了这一部分.
有没有办法使用我在OpenSSL中使用Crypto ++ API生成的RSA密钥?我正在寻找一种方法来存储密钥的格式,Crypto ++和OpenSSL都可以轻松打开它们.
我正在编写许可方案,并希望使用Crypto ++ API验证签名和解密文件,但是要生成许可证文件,我想使用Web界面(可能使用PHP,它只支持OpenSSL)来生成和加密/签署许可证.
我会使用Crypto ++编写这两个应用程序并从PHP调用它,但由于私钥将以加密形式存储,因此必须将密码传递给应用程序并在命令行上传递它似乎不太好我的想法.
我在一个相当大的文件中有以下行:
#include <sha.h>
#include <hex.h>
Run Code Online (Sandbox Code Playgroud)
在编译时会抛出此编译器错误:
1>d:\work\app\tools\cryptopp\algparam.h(322): error C2061: syntax error : identifier 'buffer'
1> d:\work\app\tools\cryptopp\algparam.h(321) : while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void *) const'
1> with
1> [
1> T=bool
1> ]
1> d:\work\app\tools\cryptopp\algparam.h(329) : see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<T>' being compiled
1> with
1> [
1> T=bool
1> ]
Run Code Online (Sandbox Code Playgroud)
我很确定我忘了什么,但我不确定是什么.如果我不包含hex.h,我没有任何问题,我得到一个SHA256哈希就好了,但是当我包含hex.h时,会弹出错误.
编辑
如果有人想知道,来自alpparam.h的Crypto ++工具包:
void MoveInto(void *buffer) const //<=== line 320
{
AlgorithmParametersTemplate<T>* p = new(buffer)
AlgorithmParametersTemplate<T>(*this);
}
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; // <== line 329
Run Code Online (Sandbox Code Playgroud)
编辑 …
通过套接字将 RSA::PublicKey 发送给另一个用户的安全方法是什么?我想将密钥导出到 ByteQueue 并将字节数组发送给用户,在那里他可以再次构造公钥。
或者这是否会泄漏可能被滥用的信息?
//Generate keys
AutoSeededRandomPool rng;
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 3072);
//Create
RSA::PublicKey publicKey(params);
//Save
ByteQueue queue;
publicKey.Save(queue);
byte publicKeyBuffer[1000];
size_t size = queue.Get((byte*)&publicKeyBuffer, sizeof(publicKeyBuffer));
//Load
RSA::PublicKey loadkey;
ByteQueue queue2;
queue2.Put2((byte *)&publicKeyBuffer, size, 0, true);
loadkey.Load(queue2);
Run Code Online (Sandbox Code Playgroud) 我正在尝试从std::string包含PEM格式的私钥的RSA私钥加载,如下所示:
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAK8Q+ToR4tWGshaKYRHKJ3ZmMUF6jjwCS/u1A8v1tFbQiVpBlxYB
paNcT2ENEXBGdmWqr8VwSl0NBIKyq4p0rhsCAQMCQHS1+3wL7I5ZzA8G62Exb6RE
INZRtCgBh/0jV91OeDnfQUc07SE6vs31J8m7qw/rxeB3E9h6oGi9IVRebVO+9zsC
IQDWb//KAzrSOo0P0yktnY57UF9Q3Y26rulWI6LqpsxZDwIhAND/cmlg7rUz34Pf
SmM61lJEmMEjKp8RB/xgghzmCeI1AiEAjvVVMVd8jCcItTdwyRO0UjWU4JOz0cnw
5BfB8cSIO18CIQCLVPbw60nOIpUClNxCJzmMLbsrbMcUtgVS6wFomVvsIwIhAK+A
YqT6WwsMW2On5l9di+RPzhDT1QdGyTI5eFNS+GxY
-----END RSA PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud)
我想知道是否有人可以帮助我使用此密钥而不是使用以下语句生成随机.
CryptoPP::RSA::PrivateKey rsaPrivate;
rsaPrivate.GenerateRandomWithKeySize (rnd, 512);
Run Code Online (Sandbox Code Playgroud) 所以我试图使用PBKDF2来获得一个给定256位256位字符串的密钥.我能够使用C#的Rfc2898DeriveBytes和node-crypto的pbkdf2来获得相同的密钥,但是,对于C++我不能说同样的.我不确定我是否进行了错误的转换或使用不正确的功能,但我会让你们看看它.
C++
/* 256bit key */
string key = "Y1Mjycd0+O+AendY5pB58JMlmS0EmBWgjdj2r2KW6qQ=";
string decodedKey;
StringSource(key, true, new Base64Decoder(new StringSink(decodedKey)));
const byte* keyByte = (const byte*) decodedKey.data();
/* Generate IV */
/*
AutoSeededRandomPool prng;
byte iv[AES::BLOCKSIZE];
prng.GenerateBlock(iv, sizeof(iv));
*/
/* FOR TESTING PURPOSES, HARDCODE IV */
string iv = "5iFv54dCRq5icQbD7QHQzg==";
string decodedIv;
StringSource(iv, true, new Base64Decoder(new StringSink(decodedIv)));
const byte* ivByte = (const byte *) decodedIv.data();
byte derivedKey[32];
PKCS5_PBKDF2_HMAC<CryptoPP::SHA1> pbkdf2;
pbkdf2.DeriveKey(derivedKey, 32, 0, keyByte, 32, ivByte, 16, 100);
/*
* derivedKey: 9tRyXCoQLTbUOLqm3M4OPGT6N25g+o0K090fVp/hflk=
*/
Run Code Online (Sandbox Code Playgroud)
C# …
我试图在我的CMakeLists文件中指定Crypto ++库,但我总是收到错误.
这是我的CMakeLists档案:
cmake_minimum_required(VERSION 2.8)
project( Recognition )
find_package( OpenCV REQUIRED )
find_package ( CURL REQUIRED )
find_package ( CRYPTOPP REQUIRED )
add_executable( Recognition Recognition.cpp )
target_link_libraries( Recognition ${OpenCV_LIBS} ${CURL_LIBRARY} ${CRYPTOPP_LIBRARY})
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
By not providing "FindCRYPTOPP.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CRYPTOPP",
but CMake did not find one.
Could not find a package configuration file provided by "CRYPTOPP" with any
of the following names:
CRYPTOPPConfig.cmake
cryptopp-config.cmake …Run Code Online (Sandbox Code Playgroud) 如何使用 SHA-256 填充而不是 Crypto++ 中的默认 SHA-1 填充来加密我的字符串数据?我无法找到任何方法来更改我的加密/解密函数使用的填充算法。我听说一些库具有硬编码的填充方案,但我希望有一种方法可以修改 Crypto++ 使用的方法。
这是我的加密方法:
string GUIMain::encryptData(const string data) {
CryptoPP::RSAES_OAEP_SHA_Encryptor e(*serverPublic);
string cipher;
CryptoPP::StringSource ss1(data, true, new CryptoPP::PK_EncryptorFilter(*rng, e, new CryptoPP::StringSink(cipher)));
return cipher;
}
Run Code Online (Sandbox Code Playgroud)
这是我的解密方法:
string GUIMain::decryptData(const string cipher) {
CryptoPP::RSAES_OAEP_SHA_Decryptor d(*privateKey);
string recovered;
CryptoPP::StringSource ss2(cipher, true, new CryptoPP::PK_DecryptorFilter(*rng, d, new CryptoPP::StringSink(recovered)));
return recovered;
}
Run Code Online (Sandbox Code Playgroud)
键(*serverPublic和*privateKey)分别是对象类型RSA::PublicKey和RSA::PrivateKey。*rng是一个AutoSeededRandomPool对象。
有什么方法可以添加/更改这些方法以使其正常工作?我是 C++ 新手,所以请尽可能解释解决方案。
我正在尝试使用 Crypto++ 库中的 AES 加密:
CBC_Mode<AES>::Encryption e;
Run Code Online (Sandbox Code Playgroud)
我有一个需要加密的二进制数据块。该类似乎提供了ProcessData为此目的调用的方法:
virtual void ProcessData(byte *outString, const byte *inString, size_t length);
Run Code Online (Sandbox Code Playgroud)
看起来最后一个参数是输入数据的大小。不清楚的是为什么该方法不返回加密数据的大小。是否假设输出数据块的大小与输入数据块的长度完全相同?即使输入数据的大小只有一个字节,这是否有效?问候。
情况
我有两个任意来源,比如说StringSource来自签名的一个和FileSource来自相应签名文件的一个。我现在想验证当前执行的文件签名,如下所示:
bool VerifyFile(const ECDSA<ECP, SHA512>::PublicKey &key,
const std::string &filename,
const std::string &signatureString) {
std::string fileContentString;
FileSource(filename.c_str(), true,
new CryptoPP::StringSink(fileContentString));
bool result = false;
StringSource(signatureString + fileContentString, true,
new SignatureVerificationFilter(
ECDSA<ECP, SHA512>::Verifier(key),
new ArraySink((byte *) &result, sizeof(result))
) // SignatureVerificationFilter
);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我的问题
我不想将文件的内容显式提取到字符串中,然后进行串联并随后进行验证。
问题
有没有一种方法可以将两个任意源传递给验证实体,其中一个表示签名,另一个表示签名内容(可能是文件或字符串)?
到目前为止我尝试过的
我尝试重定向Source::TransferAll(...)到 a ,但没有成功。RedirecterSignatureVerificationFilter