简体   繁体   English

Crypto++ GetModulus() 问题

[英]Crypto++ GetModulus() issue

My goal is the generation of a RSA 2048 bits keys pair to be used to get access to a SSH server.我的目标是生成用于访问 SSH 服务器的 RSA 2048 位密钥对。

The issue is that the modulus got from GetModulus() is not the real key's modulus.问题是从GetModulus()获得的模数不是真正的键的模数。 If I export the key in DER format the content of the modulus field is different from GetModulus() function result.如果我以 DER 格式导出密钥,则模数字段的内容与GetModulus() function 结果不同。

Below is my code for generating the keys pair:下面是我生成密钥对的代码:

// Generate keys pair
AutoSeededRandomPool lRnd;
InvertibleRSAFunction lPrms;
lPrms.GenerateRandomWithKeySize(lRnd, 2048);
RSA::PrivateKey lPrvKey(lPrms);
RSA::PublicKey lPubKey(lPrms);

// Convert private key to DER base64
Base64Encoder lB64PrvEncoder;
AlgorithmParameters lPrvPrms = MakeParameters(Name::MaxLineLength (), 64);
lB64PrvEncoder.IsolatedInitialize(lPrvPrms);
lPrvKey.DEREncodePrivateKey(lB64PrvEncoder);
lB64PrvEncoder.MessageEnd();

// Convert public key to base64 openSSH format
Integer lN = lPubKey.GetModulus();
Integer lE = lPubKey.GetPublicExponent();
QByteArray lSSHPubKey;
PubKeyToSSHFormat(lE, lN, lSSHPubKey);

Above, lN is different from the modulus found in the DER formatted private key.上面, lN与 DER 格式的私钥中的模数不同。

Any help will be really appreciated.任何帮助将不胜感激。

Thank you all for the answers.谢谢大家的回答。 I found out what the issue is and I would like to ask you an opinion about the library implementation.我发现了问题所在,我想请教您对库实现的看法。 GetModulus() returns the modulus in the "Integer" class. GetModulus() 返回“整数”class 中的模数。 That big number is stored using the endianess of the machine (Intel in my case) even tough the number is a sequence of bytes, I didn't manage the endianess.这个大数字是使用机器的字节序存储的(在我的例子中是英特尔),即使这个数字是字节序列,我也没有管理字节序。 that's why the modulus I put in the file got rejected, I didn't think about the endianess.这就是我放入文件中的模数被拒绝的原因,我没有考虑字节序。 based on my knowledge it applies only to variables with the same size of CPU's word length (or less).根据我的知识,它仅适用于具有相同大小的 CPU 字长(或更少)的变量。 In this case we have a large integer stored as a sequence of bytes.在这种情况下,我们有一个大的 integer 存储为字节序列。 Any opinion is appreciated.任何意见表示赞赏。

Best Regards此致

/Alessandro /亚历山德罗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM