저는 Crypto ++의 RSA 암호화를 사용하려고합니다. 문제는 숫자 문자열에서 RSA::PrivateKey
을 초기화하는 방법입니까?RSA :: PrivateKey를 초기화하는 방법?
(here에서) 키 쌍을 생성하는 코드
cout << hex ;
AutoSeededRandomPool rng;
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 2048);
params.SetPublicExponent(65537);
const Integer& n = params.GetModulus();
const Integer& p = params.GetPrime1();
const Integer& q = params.GetPrime2();
const Integer& d = params.GetPrivateExponent();
const Integer& e = params.GetPublicExponent();
///////////////////////////////////////
// Dump
cout << "RSA Parameters:" << endl;
cout << " n: " << n << endl;
cout << " p: " << p << endl;
cout << " q: " << q << endl;
cout << " d: " << d << endl;
cout << " e: " << e << endl;
cout << endl;
그래서 내가 N, D, E 문자열을 얻을, 개인 키를 초기화 할 수 있어야한다, 나는 몇 가지 샘플 코드 here을 발견 :
Integer n("0xbeaadb3d839f3b5f"), e("0x11"), d("0x21a5ae37b9959db9");
RSA::PrivateKey privKey;
privKey.Initialize(n, e, d);
RSA::PublicKey pubKey;
pubKey.Initialize(n, e);
코드가 작동하지만 예외가 발생하지 않습니다. 그래서 n, e, d를 이전에 생성 된 문자열로 변경하려고합니다.
// n: b0f2bee69386528216049775704d402cb3ff443ca2ea25a74b11c1c9c321b7ea46327b4e413f532616812fece07d061cf96e373789b3b9b05d2d31174c700a066868d26c52b5d48e6dbaf664fac66ee31747133a6569e16d12f521b56a12aadd74e7cf2534353a5e338173b8f884a568a25173f3a33782f9047af59da9b21180534923e5210c3989851f0d69d68d92c272769fbf2a833e2f522f60f76bec12d3b194c2f3b945c913649e2be54295a2f58e7c040bf61421f01077fdf234ddfe73663deec8979256c721fd65c046a7d21530adec1af2922ed6a27004bf31a04cd57981ca22208572743b6b64d4d30b0efe446fc7608b4178ff8a0ba7db3e45ecf3h
// e: 10001h
// d: 246e365ca5e6f2de8c100110a62e05aed9c39d1b8af3f8b1806589c7a82c96ce59bf1962ef50cd5aaa47c61a2e37db9c8db4cf2205c31eb35e7a3ed017443e4c9d0685ace3da243b70f1c951067425e375bbcf40ba86bd7856b9ff691d5e323ca720aaa5c6fbe65eb0404c87f6ee220e034d0148bfb89af70873ab09df2c30c74104b0973aa4e93ca95db749da4f6b2d9594ab487db1f6f194ab0b77bd91d834daf269c63d3abecad54a1a71599524e679a425c55b16a9ff7f0c37b2d259eb44ea5782f314f61cc0ac874b2e6ae870d798e90e5bc96ab57c8fd904fa9d199c46c971de3a5d7cabfdca0663373843bd41ec246e158754dabc9ec2172f7a5982edh
RSA::PrivateKey privKey;
privKey.Initialize(n, e, d);
충돌합니다. 나는 잠시 봤 및 some other tip을 발견
InvertibleRSAFunction params;
params.Initialize(n, e, d);
RSA::PrivateKey(params);
하지만 여전히 충돌합니다. 2048 비트 rsa 개인 키를 초기화하는 올바른 방법은 무엇입니까?
그래서'RSA_PUB_KEY'는 실제로 모듈입니까? –
문자열을 어떻게 든 변경 했습니까? 문서에 따르면 16 진수로 인코딩 된 정수는 'h'로 끝나야합니다. 'std :: ostream & operator <<'를 보라. http://www.cryptopp.com/docs/ref/class_integer.html#aa5f24aab6821fe59b7b161682b9a40cd –
private_key와 public_key가 두 개의 홀수 인 것이 맞는지 잘 모르겠다. 그들은 서로를 대체 할 수 있습니다. 그리고 나는 cout <<에서 출력되는 문자열을 수정했습니다. 그것은 .h로 끝나고, 그것을 제거하고 "0x"를 추가하기 전에, CryptoPP :: Integer에 대해 괜찮아 보입니다. – aj3423