RSA encryption: using modulus and exponent to generate public key encryption

Source: Internet
Author: User
Tags modulus openssl library

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...

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.