rsaEncrypt.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import JSEncrypt from './jsencrypt'
  2. // import JSEncrypt from '../node_modules/jsencrypt/bin/jsencrypt.js'
  3. // 密钥对生成 http://web.chacuo.net/netrsakeypair
  4. const publicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5EcZCw8a2QAwGwuDk/d
  5. +AQDKwqye2OG73gKvoUCkH2H47XtUHw9MOGYtG44BXrh4KYM0YqZrZIPu4FZzFTs
  6. 0wAyhzAHRXray0l/kAfCHtI+A9bwqOwbtBFOrL2lOCuVHptEE+RPmO4v7UCGcYIK
  7. umb0/cOtvXAa0yM5V9kxrGXpavsLPsoB5kWQwnelW/mYyIEm4Rtvh9uKsTyfkb80
  8. cxJtQNlq1sOrh0dR0aSIdDGnqCrtsaNw19UBQtOe5JsdXSeZYff9vuT9lwtjvkta
  9. k4hI3IwtmR1STTVp8ZJ+6Oumu+QCDQvNGHzX5oBumiGPmDqPd2wyTnFsDPypc685
  10. MwIDAQAB`
  11. const privateKey = `MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7kRxkLDxrZADA
  12. bC4OT934BAMrCrJ7Y4bveAq+hQKQfYfjte1QfD0w4Zi0bjgFeuHgpgzRipmtkg+7
  13. gVnMVOzTADKHMAdFetrLSX+QB8Ie0j4D1vCo7Bu0EU6svaU4K5Uem0QT5E+Y7i/t
  14. QIZxggq6ZvT9w629cBrTIzlX2TGsZelq+ws+ygHmRZDCd6Vb+ZjIgSbhG2+H24qx
  15. PJ+RvzRzEm1A2WrWw6uHR1HRpIh0MaeoKu2xo3DX1QFC057kmx1dJ5lh9/2+5P2X
  16. C2O+S1qTiEjcjC2ZHVJNNWnxkn7o66a75AINC80YfNfmgG6aIY+YOo93bDJOcWwM
  17. /KlzrzkzAgMBAAECggEAQaVK84BL8SYB4Va7U8T+IeR9m13WE7tEqaEw2XdB64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BAOXXoxO6sWbpWTI1yBhN
  34. sG6576FPksdV8cJKQAT9zaQFXl+K0aXx0aADZrpm0jA7zL1jrUEvtWIeiDJ47Sdq
  35. tsob57LKyjiUqJT+rG0F1UMhXX4Bhx0/itmTzoXMFg2x4gCLLDsse4OYSprsZFxY
  36. EZ1+TtYg/zZVCOPJk39N8mIX`
  37. // 加密
  38. function encrypt(txt) {
  39. const encryptor = new JSEncrypt()
  40. encryptor.setPublicKey(publicKey) // 设置公钥
  41. return encryptor.encrypt(txt) // 对需要加密的数据进行加密
  42. }
  43. // 解密
  44. function decrypt(txt) {
  45. const encryptor = new JSEncrypt()
  46. encryptor.setPrivateKey(privateKey)
  47. return encryptor.decrypt(txt)
  48. }
  49. export default {
  50. encrypt,
  51. decrypt
  52. }