What is RSA asymmetric encryption

  • Party B generates a pair of keys (public key and private key), and discloses the public key to Party A
  • After Party A obtains the public key, it will encrypt the data to be transmitted with the public key and send it to Party B
  • After Party B obtains the encrypted data of Party A, it uses the private key to decrypt it
    In the process of data transmission, even if the data is intercepted by the attacker and the public key is obtained, the attacker cannot* crack the ciphertext, because only the private key of Party B can decrypt it

Prepare a pair of public and private keys

  • Online generation tool
  • keytool

Front-end encryption core code

Key: encodeURI(str).replace(/+/g,'%2B')

Processing of + sign: Because when data is transmitted on the network, non-alphanumeric characters will be replaced with a percent sign (%) followed by two hexadecimal digits, and when base64 encoding is transmitted to the backend, + will be It becomes a space, so replace it first. Replace the backend

var encrypt = new JSEncrypt (); encrypt.setPublicKey ( 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDO5hYr37o95clKDRoMIpFHw1sbh078PoTgRMuHprYnVYzpCMevKoc / q5R8HA2wTrheTfAZoA8jX4KYsUbUFa / 2 + 9ADVmH2WtPwN8VP7NX7WO + kGP + tGtnE + 55rvatZVfUza + 0 + N2WqYSvioFlS99nU6nFSIBaqUU6SR0CgaG4oowIDAQAB');

encodeURI(encrypt.encrypt($('#txtcontact').val())).replace(/\+/g,'%2B')

Backend decryption core code

$ Txtname = "jhi78KJV73x6Ej8DoVSQmzLVqBQtDlLsGjRbVUhqlcR78tPBPDD% 2BsAvPRIa8oYsK3Fx8CfAMBcUu5Rqk5xn0tOKqW5frCcMUU7dqJEqsPKwhg% 2BvYIAr5e5dwToVmzee2jecUHruMZK20m% 2BCx% 2BC / bXFvbwaDm5Cwgnw9% 2BV4LT0pI =";
$txtname = str_replace('%2B','+',$txtname);
$txtname = base64_decode($txtname);
点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部