Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest to add judgment when string too long #292

Open
CreatorEdition opened this issue Apr 3, 2023 · 0 comments
Open

Suggest to add judgment when string too long #292

CreatorEdition opened this issue Apr 3, 2023 · 0 comments

Comments

@CreatorEdition
Copy link

Suggest to add judgment when string too long
If the string is too long, it should be encrypted by dividing it into blocks.
I've seen many people react and think that this is a bug.

        /**
         * Encrypt long strings by segmenting them.
         * @param {string} str the string to encrypt
         * @return {string} the encrypted string encoded in base64
         * @public
         */
        encryptLong: function(str,$key) {
            var encryptor = new JSEncrypt();
            encryptor.setPublicKey($key);
            var maxChunkLength = 100,
                output = '',
                inOffset = 0,
                outOffset = 0;
            while (inOffset < str.length) {
                console.log(str.substring(inOffset, inOffset + maxChunkLength));
                output += encryptor.encrypt(str.substring(inOffset, inOffset + maxChunkLength));
                inOffset += maxChunkLength;
            }
            return output;
        },
        /**
         * Decrypting long texts
         * @param {string} string The base64 encoding of the encrypted message.
         * @returns {string} Decrypted original text
         */
        decryptLong: function(string,$key) {
            var decryptor = new JSEncrypt();
            decryptor.setPrivateKey($key);
            var maxChunkLength = 172,
                output = '',
                inOffset = 0,
                outOffset = 0;
            while (inOffset < string.length) {
                console.log(string.substring(inOffset, inOffset + maxChunkLength));
                output += decryptor.decrypt(string.substring(inOffset, inOffset + maxChunkLength));
                inOffset += maxChunkLength;
            }
            return output;
        },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant