我是第一次使用Crypto ++,我遇到了一些麻烦.为什么这在C#中使用(使用相同的密钥),而不是在Crypto ++中?我将在下面展示我的C#和C++代码.
C#代码(这有效!):
byte[] Modulus = new byte[] { 0xA3, 0x1D, 0x6C, 0xE5, 0xFA, 0x95, 0xFD, 0xE8, 0x90, 0x21, 0xFA, 0xD1, 0x0C, 0x64, 0x19, 0x2B, 0x86, 0x58, 0x9B, 0x17, 0x2B, 0x10, 0x05, 0xB8, 0xD1, 0xF8, 0x4C, 0xEF, 0x53, 0x4C, 0xD5, 0x4E, 0x5C, 0xAE, 0x86, 0xEF, 0x92, 0x7B, 0x90, 0xD1, 0xE0, 0x62, 0xFD, 0x7C, 0x54, 0x55, 0x9E, 0xE0, 0xE7, 0xBE, 0xFA, 0x3F, 0x9E, 0x15, 0x6F, 0x6C, 0x38, 0x4E, 0xAF, 0x07, 0x0C, 0x61, 0xAB, 0x51, 0x5E, 0x23, 0x53, 0x14, …Run Code Online (Sandbox Code Playgroud) 我试图在Crypto ++中使用SecretSharing类,但我无法使其工作.
这是我的代码:
using namespace CryptoPP;
void secretSharing(){
AutoSeededRandomPool rng;
SecretSharing shamir(rng, 4, 6);
byte test[] = {'a', 'b', 'c', 'd'};
shamir.Put(test, 4);
//shamir.MessageEnd();
//cout << shamir.TotalBytesRetrievable() <<endl;
}
Run Code Online (Sandbox Code Playgroud)
编译运行后,我会得到:
./main
terminate called after throwing an instance of 'CryptoPP::BufferedTransformation::NoChannelSupport'
what(): unknown: this object doesn't support multiple channels
[1] 3597 abort (core dumped) ./main
Run Code Online (Sandbox Code Playgroud)
声明SecretSharing::SecretSharing()是:
SecretSharing (RandomNumberGenerator &rng, int threshold, int nShares, BufferedTransformation *attachment=NULL, bool addPadding=true)
我应该给它一个BufferedTransformation*,但我应该使用哪个类?
Crypto ++中是否有任何秘密共享示例代码?
我已经实现了我的AES 256加密方法,并且可以在Java中正常工作,如下所示!
private static final byte[] IV = {
0, 2, 4, 8, 16, 32, 64, 127,
127, 64, 32, 16, 8, 4, 2, 0
};
//actual encryption over here
private static byte[] encrypt(byte[] raw, byte[] clear) throws
Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = null;
if(isIVUsedForCrypto) {
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(IV));
}
else
{
cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
}
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
Run Code Online (Sandbox Code Playgroud)
从上述方法返回的字节数组最终使用以下toHex方法转换为HEX字符串。
public static …Run Code Online (Sandbox Code Playgroud) 我独立学习C++,我有一个问题,我不能解决超过一周的问题.我希望你能帮助我.
我需要获取Unicode字符串的SHA1摘要(如??????),但我不知道如何做到这一点.
我尝试这样做,但它返回错误的摘要!
因为wstring('?')
它返回 - A469A61DF29A7568A6CC63318EA8741FA1CF2A7
我需要 -8dbe718ab1e0c4d75f7ab50fc9a53ec4f0528373
关心并抱歉我的英语:).
CryptoPP 5.6.2 MVC++ 2013
#include <iostream>
#include "cryptopp562\cryptlib.h"
#include "cryptopp562\sha.h"
#include "cryptopp562\hex.h"
int main() {
std::wstring string(L"?");
int bs_size = (int)string.length() * sizeof(wchar_t);
byte* bytes_string = new byte[bs_size];
int n = 0; //real bytes count
for (int i = 0; i < string.length(); i++) {
wchar_t wcharacter = string[i];
int high_byte = wcharacter & 0xFF00;
high_byte = high_byte >> 8;
int low_byte = wcharacter & 0xFF; …Run Code Online (Sandbox Code Playgroud) 如前所述这里,消息签名的长度等于私钥的模数,又称公钥.
我正在实现一个签署消息的系统,而且我的大小不匹配是我无法解决的.我用crypto++.
这是我使用的代码:
/* Create RSA Keys */
RSA::PrivateKey privateKey;
privateKey.GenerateRandomWithKeySize(prng, 3072);
RSA::PublicKey publicKey(privateKey);
cout << ">> RSA Keys generated";
/* Key Size */
string spki;
StringSink sSink(spki);
publicKey.Save(sSink);
cout <<" ("<< spki.size()<<" bytes)"<<endl;
RSASSA_PKCS1v15_SHA_Signer signer(privateKey);
size_t length = signer.MaxSignatureLength();
cout <<"MaxSignatureLength " <<length<<endl;
SecByteBlock signature( length );
Run Code Online (Sandbox Code Playgroud)
输出是:
>> RSA Keys generated (420 bytes)
>> ServerHello sent (436 bytes)
MaxSignatureLength 384
RSA Signature length 384
Run Code Online (Sandbox Code Playgroud)
不应该MaxSignatureLength,和RSA Signature length420字节长?
我使用的算法有问题吗?
我创建了一个示例项目,它使用Crypto ++的本机C++库和NDK来生成一些ECDH密钥对.你可以在这里找到这个项目.
这个项目在大多数Android设备上都运行得很好(在少数4.4和5.0设备上运行).但是我最近在运行Android 6.0.1的Nexus 5和Nexus 7上运行了该应用程序,该应用程序因以下错误而崩溃.
java.lang.UnsatisfiedLinkError: dlopen failed: library "./obj/local/armeabi-v7a/libcryptopp.so" not found
Run Code Online (Sandbox Code Playgroud)
我不确定这里发生了什么,因为该项目显然有这些文件,他们应该没问题.这似乎可能是某种与NDK相关的问题,但我不太确定.
我尝试删除armeabi-v7a文件夹,这迫使该应用程序使用Nexus设备上的armeabi文件,但它也找不到这些文件.
我打开了apk,所有正确的.so文件都在那里,并带有相应的文件夹.
不确定这是Android Marshmallow问题,Nexus架构问题还是某些.so文件编译问题.我是使用NDK的新手,所以我希望能找到解决这个问题的想法.
编辑:看了一下后,看起来这是一个Android Marshmallow问题.这里提到了一个相关的问题.改变我targetSdkVersion以22"修复"崩溃.但显然这不是一个非常友好的解决方案.
显然在Android Marshmallow上,他们从OpenSSL切换到BoringSSL.这可能是根本问题,因为我认为Crypto ++使用OpenSSL的功能并链接它?
还在四处寻找能让我真正解决的问题targetSdkVersion 23.可能会尝试本文中列出的一些解决方案,看看会发生什么.
编辑2:Crypto ++没有链接OpenSSL所以那就是理论.这里的帮助仍然很感激.
我正在尝试构建libcryptopp.so并将其包含在我的JNI代码中,遵循Android Crypto ++中的指南,我遇到了以下问题.
Crypto ++ 5.6.3中缺少符号问题
最初我使用Crypto ++ 5.6.3,我遇到了这个问题:
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_Z9GlobalRNGv"
referenced by "/data/app/com.example.administrator.jnitest-2/lib/arm/libcryptopp.so"...
Run Code Online (Sandbox Code Playgroud)
我查了一下libcryptopp.so:
$ readelf -Ws libcryptopp.so | grep _Z9GlobalRNGv
1406: 00000000 0 NOTYPE GLOBAL DEFAULT UND _Z9GlobalRNGv
15836: 00000000 0 NOTYPE GLOBAL DEFAULT UND _Z9GlobalRNGv
Run Code Online (Sandbox Code Playgroud)
切换到Crypto ++ 5.6.4修复此问题,但我仍然不知道原因并遇到另一个问题:
缺少DT_SONAME
12-21 09:50:20.837 21677-21677/com.example.administrator.jnitest
W/linker: /data/app/com.example.administrator.jnitest- 1/lib/arm/libcryptopp.so: is missing DT_SONAME will use basename as a
replacement: "libcryptopp.so"
Run Code Online (Sandbox Code Playgroud)
实际上这只是一个警告,应用程序不会崩溃.
我使用的是最新版本的android Mashwallow MOB31K.有人在使用其他库时也遇到了类似的问题
https://github.com/bytedeco/javacpp-presets/issues/188
Run Code Online (Sandbox Code Playgroud)
在Android N预览上.
为什么我会收到警告,如何解决?
我正在使用MinGW 5.3.0和Crypto ++ 5.6.5:
C:\MinGW>g++ -std=c++11 -s -D_WIN32_WINNT=0x0501 LOG.cpp -U__STRICT_ANSI__ Decclass.cpp \
-IC:\\MinGW\\ -IC:\\MinGW\\boost -LC:\\MinGW -lssl -lcrypto -lcryptopp -lgdi32 -lPCRYPT \
-lz -ltiny -lwsock32 -lws2_32 -lShlwapi
Run Code Online (Sandbox Code Playgroud)
编译会导致以下错误。
c:\mingw\cryptopp565\include\cryptopp\misc.h:287:14: error: 'mutex' in namespace 'std'
does not name a typestatic std::mutex s_mutex;
c:\mingw\cryptopp565\include\cryptopp\misc.h:296:18: error: 'mutex' is not a member of
'std'std::lock_guard<std::mutex> lock(s_mutex);
Run Code Online (Sandbox Code Playgroud)
它显示“ mutex”不是“ std”的成员
我需要其他版本的MinGW吗?还是我可以自己修复此版本?
我有一个以这种方式创建的签名:
size_t siglenth = _signer.MaxSignatureLength();
QByteArray signature(siglenth, 0x00);
signature.reserve(siglenth);
siglenth = _signer.SignMessage(_prng,
(const CryptoPP::byte*) (message.constData()),
message.length(), (CryptoPP::byte*) signature.data());
Run Code Online (Sandbox Code Playgroud)
我的签名大小为 64,包含:
ECCD530E5F232B7C566CA5322F990B3D55ED91156DF3845C4B9105BFE57606DDD68F332A0A5BF7CAB673E4970D10109B72F11457ACD78CED11457ACD7894ED
从我在dsa.h文件中阅读的内容来看,这个签名目前是DSA_P1363格式。我需要将其转换为DSA_DER格式。
要执行此操作,我尝试:
QByteArray derSign(70, 0xFF);
size_t converted_size = CryptoPP::DSAConvertSignatureFormat(
(CryptoPP::byte*) (derSign.data()), sizeof(derSign.data()), CryptoPP::DSA_DER,
(CryptoPP::byte*) (signature.data()), sizeof(signature.data()), CryptoPP::DSA_P1363);
Run Code Online (Sandbox Code Playgroud)
此转换的输出如下所示。它似乎只是签名的第一部分。它的大小为 8,包含:
300D020500ECCD53
怎么了?
谢谢。
我目前正在使用Crypto ++为数据块生成签名.我希望签名是20个字节(SHA 1哈希),因为我的理解是签名只是一个加密的哈希.但是在使用maxsignaturelength和签名长度进行检查时,它似乎是192个字节.这是正常的吗?