Does anyone understand the segmented decryption of jsencrypt long strings?

what if the decryption string using jsencrypt is too long and the decryption content is solved by Null?
address jsencrypt: https://github.com/travist/js.
website has found some but can not use many incomplete
to solve this problem.

import JSEncrypt from "jsencrypt";
var RSA = new JSEncrypt();
    /*
       
       * content (String)
       * mode (String)
       * */
    static decrypt(content,mode="RSA"){
        if(!content){
            console.log("");
            return "";
        }
        let res;
        let key;
        switch(mode){
            case "RSA":
                //
                key = "XXX"
                console.log("",content);
                RSA.setPrivateKey(key);
                res = RSA.decrypt(content);
                console.log("res",res);//null 
                break;
        }
        return res;
    }

I am also using this library. I tried a few days ago to group a large piece of JSON strings into 117characters, and then a single group uses RSA encryption, that is, public key encryption. The other party can only decrypt it with a private key, and then write the grouped encrypted string into a JSON, so that the action can be successful, and the other party can decrypt successfully, but it is relatively slow, obviously it takes a period of time.

all, a better solution is that only sensitive fields are encrypted with RSA, and others are not encrypted.
the final total string uses sha256 to get a summary. Finally, the summary is encrypted only by RSA, and the original text is sent to the other party after RSA encryption.

after the other party receives it, unlock the abstract with the private key and make a summary of the original character again to compare whether the two abstracts are equal. This is also the method used by Alipay.


you should describe the problem in code, so that someone can answer


it is not recommended to encrypt very long strings like this, which is worrying about speed.


it is not recommended to use RSA to encrypt large amounts of data because of performance problems. However, we have already done it in the background, so we cannot change it. At the beginning, we also wrote a segmented encryption and decryption using js, which can be used, but we encountered some problems. Garbled codes will occur after the body characters are merged and decrypted again in the encryption and decryption. Finally put the decryption part to the original.

Menu