Requirements: The original password of the user in the project must be passed to the backend, because the backend has to call a third-party interface with the password. If the password is not transmitted in plaintext very well, if it is caught by the packet capture tool, the password will be leaked. The RSA algorithm was eventually adopted, with the front end encrypting the password using the public key and the back end using the private key to decrypt it.
The frontend uses the jsencrypt package, address:The hyperlink login is visible.
If the backend is .NET 5 or above, you can use the built-in functions, if not, please use the following parameters:
First, use openssl to generate public and private keys, this article is executed directly on Linux (please download and install openssl on Windows system), the command is as follows:
cat rsa_1024_priv.pem -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDTyd/KP2JuidA0JA+7i8FCzKCdn2Gq/ChfLpnBFcHb9vKgZb6n aK2UXynpTbO6l5CVU4KG7w/hUJgxUQsSzNIsnPQuNpop/FO9doiV5l/94Hcuj17f 2AAEQGkWC8EvZBoMDr2JRVDBEji3l6mHXmTduCjH7VpuQyJRGHzWQu8HnwIDAQAB AoGARat4Ifkd8U0Gn9BpGIIN7mKQR6nhoDTZNw6GZ903a5veDuPJhxrJVzDDAcuc 3znyxxy0qJzF9ZHkrvyBDwsv7AGyVfg6fwwLxvrsJS1MpwKLY3yqbPVk3hnaOECO 915XcbkVua+DGVjwtyX37CxPuSDaH2ut+kIQ3xci+BreSpkCQQD3FfgYELZgrHDk JQaSiILCnFbld+NBuTm4CHPCN+XDZwzvC8sH4M9my7kznxAQosHbm+aGaOK1k4+k zKgaiJzVAkEA223oSa7UMyMf/K/dEFmGjKBWQYP7gjLxcsxDHdwTpKHBEuZ32IT2 nuvYxsaOATqg8WABAJHWmT2Rj/joeAx8owJBANaLovLygAoNcbEIXV6bXj8xlVqG 8TO+a9narPk1pDI5psdijBb5I930g4nJUh+/02inRFHtfP2Bdbb5ZfY0LUkCQDxJ iCamaBrcra8pSl1xm2wLqWc6seFlyby2rkIH80WqQ3fD5m2QqomjVt3WM7HWv91R eTUE3KchqVqbEpPZKm0CQD7VMRAb1NNH+BNjuGxZB3AQSJvRXhpJ+w3ckSP6IX0L N0OoHtvH5lvtm7hfB5nDUBYhqN3wj7wDNiK9Vrdyqow= -----END RSA PRIVATE KEY----- cat rsa_1024_pub.pem -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTyd/KP2JuidA0JA+7i8FCzKCd n2Gq/ChfLpnBFcHb9vKgZb6naK2UXynpTbO6l5CVU4KG7w/hUJgxUQsSzNIsnPQu Npop/FO9doiV5l/94Hcuj17f2AAEQGkWC8EvZBoMDr2JRVDBEji3l6mHXmTduCjH 7VpuQyJRGHzWQu8HnwIDAQAB -----END PUBLIC KEY----- Create a new index.html webpage with the following source code:
Tourists, if you want to see the hidden content of this post, please Reply
Create a new .NET 8 console application with the following source code:
Open the index.html web page using a browser, test the encryption, and use the .NET application to decrypt it, as shown in the following figure:
Note: Both encryption and decryption of very long strings will fail, and segmented encryption and decryption are required. For specifics, you can refer to:The hyperlink login is visible.
(End)
|