我需要使用使用SHA1的Crypto ++生成随机哈希.目前我有:
#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
...
CryptoPP::SHA1 sha1;
string source = "Hello"; //This will be randomly generated somehow
string hash = "";
StringSource(source, true, new HashFilter(sha1, new HexEncoder(new StringSink(hash))));
Run Code Online (Sandbox Code Playgroud)
当我来编译时,我收到以下错误报告:
error: expected type-specifier before 'HashFilter'
error: expected ')' before 'HashFilter'
error: 'StringSource' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
谁能帮助我让这个工作?有没有一种更简单的方法来使用这个库执行此操作?我是使用Crypto ++的新手,所以非常感谢所有的帮助.
谢谢.
我需要加密单个 AES 块。我不能使用任何模式,如 CBC 和其他。我所看到的每个示例都使用流模式。
编辑:好的,我用下一种方式做了,但我真的不喜欢这种尝试。
void dec(const byte *key, const byte* xblock, const byte *cipher, byte *plain) {
AESDecryption d;
try {
const NameValuePairs &nvp = MakeParameters("", 0);
d.UncheckedSetKey(key, 16, nvp);
d.ProcessAndXorBlock(cipher, xblock, plain);
}
catch(...) {}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Qt 应用程序中使用 Crypto++ 库。
Qt 版本为 5.3.0 在 Windows 8.1 上运行 VS2013 编译
用 VS2013 编译的 Crypto++ Lib
这是我的 .pro 文件中链接 lib 的部分
win32: LIBS += -L$$PWD/cryptopp562/Win32/DLL_Output/Release/ -lcryptopp
INCLUDEPATH += $$PWD/cryptopp562
DEPENDPATH += $$PWD/cryptopp562
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好。但是我有两个问题。
我无法编译调试版本。我认为这是因为我有 .lib 文件的发布版本
当我尝试编译我的应用程序时,出现以下错误
crypto.obj:-1: 错误: LNK2019: 未解析的外部符号 "class std::basic_string,class std::allocator > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@ D@std@@V?$allocator@D@2@@std@@B) 在函数“public: virtual bool __thiscall CryptoPP::Unflushable::Flush(bool,int,bool)”中引用 (?Flush@?$ Unflushable@VFilter@CryptoPP@@@CryptoPP@@UAE_N_NH0@Z)
我收到两个这样的错误,我认为这是由于两个调用 lib 的函数没有被编译。
我的观察:
似乎我正在链接到正确的静态库,即 libcrypt.lib,并且我使用了 dumpbin 实用程序来确保错误指定的缺失符号存在于 lib 文件中。
看来,虽然我在 .pro 文件中指定了一些 lib 没有被项目引用的方式。我已将以下行放在我的 .pro 文件中以引用静态库
win32:LIBS += -L$$PWD/cryptopp562/Win32/Output/Release/-lcryptlib …
我正在使用CryptoPP生成RSA密钥对,以允许对游戏服务器进行身份验证.我需要base64URL编码我的公共指数和模数以包含在JWK中但是我遇到了一些问题.代码显示了我如何生成RSA密钥,提取指数并对其进行编码:
typedef InvertibleRSAFunction RSAPrivateKey;
typedef RSAFunction RSAPublicKey;
RSAPrivateKey privateKey;
privateKey.Initialize( rng, 1024);
RSAPublicKey publicKey( privateKey );
const Integer& e = privateKey.GetPublicExponent();
Base64Encoder exponentSink(new StringSink(exponentString));
e.DEREncode(exponentSink);
exponentSink.MessageEnd();
base64URL(exponentString);
cout << "exponentString: " << exponentString << endl;
Run Code Online (Sandbox Code Playgroud)
base64URL函数只过滤=,+,\n和/字符的字符串,使其成为base64URL.
我知道CryptoPP使用的指数为17,上面的代码将其编码为"AgER".我从众多来源中读到65537编码为"AQAB",我通过手动设置e来尝试将其作为测试.当我这样做时,输出是"AgMBAAE",而不是"AQAB".
当我使用https://www.base64encode.org/等在线转换器时,输出是"NjU1Mzc".
有人可以解释所有这些差异来自何处以及17的正确编码是什么?谢谢!
我在加密之前使用Gzip来压缩数据.
Gzip gz;
gz.Put(file,size)
gz.MessageEnd();
gz.Get(file,gz.MaxRetrievable());
Run Code Online (Sandbox Code Playgroud)
我希望创建的gzip文件包含原始文件名作为元数据.我如何通过Crypto ++界面执行此操作?
我在尝试转换SecByteBlock为字符串时遇到问题。这是我的情况:
我想使用带有静态密钥和动态 iv 的 AES 加密用户访问数据。我的代码是这样的:
AesKeyIvFactory aesKeyIvFactory;
SecByteBlock key = aesKeyIvFactory.loadKey();
SecByteBlock iv = aesKeyIvFactory.createIv();
encryptionService->encode(&userAccess, key, iv);
std::string token = std::string(iv.begin(), iv.end()) + userAccess;
Run Code Online (Sandbox Code Playgroud)
上面的代码应该是:
从文件加载密钥;
创建四;
加密(AES)用户访问数据;
将iv与加密的用户数据访问连接起来,创建一个“令牌”;
多次运行测试,有时(1 到 10 次)std::string(iv.begin(), iv.end())无法正常工作。iv 中似乎有一个“换行符”,导致转换失败。
我尝试了很多东西,但没有任何效果,而且我没有使用 C++ 的经验。
我希望有人可以帮助我。
谁能推荐一个有 API 并支持模拟交易的币安吗?我目前正在尝试币安 webhook,并希望在不冒真钱风险的情况下测试一些策略。不幸的是,币安不支持纸质交易......
我想在Android NDK项目中包含Crypto ++(http://www.cryptopp.com/).我希望能够从我的代码的C++部分调用Crypto ++成员函数.我想我可以在我的C++代码中包含来自Crypto ++的头文件和源码,但我似乎无法让它工作.
我的C++文件如下所示:
#include <jni.h>
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
using namespace CryptoPP;
...
Run Code Online (Sandbox Code Playgroud)
与cryptopp子目录中的所有Crypto ++头文件和源文件一起使用.
最初我收到很多编译错误,因为没有找到标准的C++库,但是我通过添加Application.mk修复了以下行:
APP_STL := stlport_static
Run Code Online (Sandbox Code Playgroud)
使用ndk-build(标准版和结构版)进行编译会给出以下错误:
ABI='armeabi'
ABI='armeabi-v7a'
ABI='x86'
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : ndk-tests-cpp <= ndk-tests.cpp
In file included from jni/cryptopp/modes.h:7,
from jni/ndk-tests.cpp:2:
jni/cryptopp/cryptlib.h: In static member function 'static void CryptoPP::NameValuePairs::ThrowIfTypeMismatch(const char*, const std::type_info&, const std::type_info&)':
jni/cryptopp/cryptlib.h:291: error: exception handling disabled, use -fexceptions to enable
make: *** [obj/local/armeabi/objs-debug/ndk-tests-cpp/ndk-tests.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我之前从未在NDK项目中包含外部库 - 也许我只是忽略了一些基本的东西.
我下载了Crypto++5.62并使用默认项目设置构建它.在我的项目中,我设置了路径,cryptopp.lib并在"附加依赖项"中定义了它的名称.Crypto ++和我的项目 - VS 2008.
在构建我的项目期间,我得到:
main.obj : error LNK2001: unresolved external symbol
"class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)
main.obj : error LNK2001: unresolved external symbol
"bool (__cdecl* CryptoPP::g_pAssignIntToInteger)(class type_info const &,void *,void const *)" (?g_pAssignIntToInteger@CryptoPP@@3P6A_NABVtype_info@@PAXPBX@ZA)
Run Code Online (Sandbox Code Playgroud)
dumpbin /all cryptopp.lib 在公共符号部分显示我
19471C _imp_?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B
1D6F30 __imp_?g_pAssignIntToInteger@CryptoPP@@3P6A_NABVtype_info@@PAXPBX@ZA
Run Code Online (Sandbox Code Playgroud)
那怎么了?为什么链接器找不到符号?
UPD:
我的项目设置中的链接器命令行
/OUT:"C:\Projects\crypto_hash\Debug\crypto_hash.exe" /NOLOGO /LIBPATH:"e:\libs\cryptopp\cryptopp562\cryptopp\Win32\DLL_Output\Debug" /MANIFEST /MANIFESTFILE:"Debug\crypto_hash.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Projects\crypto_hash\Debug\crypto_hash.pdb" /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT cryptopp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
crypto++ ×10
c++ ×8
aes ×1
android ×1
android-ndk ×1
api ×1
base64 ×1
binance ×1
block-cipher ×1
cryptography ×1
encoding ×1
encryption ×1
gzip ×1
hash ×1
licensing ×1
python ×1
qt5 ×1
rsa ×1
security ×1
trading ×1