You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.8 KiB

1 year ago
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script>
  6. import JSEncrypt from './jsencrypt.min.js';
  7. export default {
  8. data() {
  9. return {
  10. }
  11. },
  12. methods: {
  13. },
  14. getRealLen:function(str) {
  15. return str.replace(/[^\x00-\xff]/g, '__').length;
  16. },
  17. setEncryptList:function(publicKey,str,max) {
  18. var arr=[]
  19. var s=str,reg=/.{40}/g,ppstr=s.match(reg);
  20. ppstr.push(s.substring(ppstr.join('').length));
  21. for (var nux=0;nux<ppstr.length;nux++) {
  22. var Nax=this.getRealLen(ppstr[nux]);
  23. if(Nax>116){
  24. var list=this.setEncryptList(publicKey,ppstr[nux],Nax)
  25. for (var nu=0;nu<list.length;nu++) {
  26. arr.push(list[nu]);
  27. }
  28. }else{
  29. arr.push(this.setEncrypt(publicKey,ppstr[nux]));
  30. }
  31. }
  32. return arr;
  33. },
  34. setEncrypt:function(publicKey,data){
  35. const encrypt =new JSEncrypt();
  36. encrypt.setPublicKey(publicKey);
  37. return encrypt.encrypt(data);
  38. },
  39. setLongEncrypt:function(publicKey,data){
  40. var s=data,reg=/.{116}/g,rs=s.match(reg);
  41. rs.push(s.substring(rs.join('').length));
  42. var arr=[];
  43. for (var n=0;n<rs.length;n++) {
  44. var max=this.getRealLen(rs[n]);
  45. if(max>116){
  46. var list=this.setEncryptList(publicKey,rs[n],max)
  47. for (var nu=0;nu<list.length;nu++) {
  48. arr.push(list[nu]);
  49. }
  50. }else{
  51. arr.push(this.setEncrypt(publicKey,rs[n]));
  52. }
  53. }
  54. return arr;
  55. },
  56. setDecryptArray:function(PrivateKey,ArrayData){
  57. var Decrypt="";
  58. for (var n=0;n<ArrayData.length;n++) {
  59. Decrypt=Decrypt+this.setDecrypt(PrivateKey,ArrayData[n]);
  60. }
  61. return Decrypt;
  62. },
  63. setDecrypt:function(PrivateKey,data){
  64. const encrypt =new JSEncrypt();
  65. encrypt.setPrivateKey(PrivateKey);
  66. return encrypt.decrypt(data);
  67. }
  68. }
  69. </script>
  70. <style>
  71. </style>