Introduction
Currently, as a financial product that involves financial security, it uses a dynamic public key, that is, each time the client logs on to the server, a different XML string is returned, which consists of the module and index of the public key, I need to use this string to generate a public key to encrypt relevant information.
The XML string returned by the server is as follows: "<rsakeyvalue> <modulus> wvwbkuepo3zzbz // signature/BFW + 79 gwnuij + signature/Signature + Signature = </modulus> <exponent> aqab </exponent> </rsakeyvalue>"
We recommend reading this blog to quickly learn about RSA: http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html
Problem
- I don't know about RSA.
- How to use the so-called modulus and exponent to generate a public key to encrypt relevant information.
Process
Familiar with RSA. Let's take a look at the definition of the RSA struct in the OpenSSL library.
struct rsa_st{/* The first parameter is used to pickup errors where* this is passed instead of aEVP_PKEY, it is set to 0 */int pad;long version;const RSA_METHOD *meth;/* functional reference if ‘meth‘ is ENGINE-provided */ENGINE *engine;BIGNUM *n;BIGNUM *e;BIGNUM *d;BIGNUM *p;BIGNUM *q;BIGNUM *dmp1;BIGNUM *dmq1;BIGNUM *iqmp;/* be careful using this if the RSA structure is shared */CRYPTO_EX_DATA ex_data;int references;int flags;/* Used to cache montgomery values */BN_MONT_CTX *_method_mod_n;BN_MONT_CTX *_method_mod_p;BN_MONT_CTX *_method_mod_q;/* all BIGNUM values are actually in the following data, if it is not* NULL */char *bignum_data;BN_BLINDING *blinding;BN_BLINDING *mt_blinding;};
View code
The blog that started the recommendation contains an introduction to the RSA modulus and exponent. The corresponding structure is N and E, and the modulo inverse number corresponds to D. The initial prime number factor corresponds to p and q. N and E determine the public key, and N and D determine the private key. Other elements in the struct can be known to generate public keys by modulus and exponent.
To be continued...