GithubHelp home page GithubHelp logo

Comments (2)

spacewander avatar spacewander commented on July 30, 2024

作为块加密算法,每个 RSA 加密之后的块大小为 128 字节。所以你可以按 128 字节进行分割,逐块解密后合并起来。

看下面的例子:

            local resty_rsa = require "resty.rsa"
            local pub, err = resty_rsa:new({ public_key = RSA_PUBLIC_KEY })
            if not pub then
                ngx.say("new rsa err: ", err)
                return
            end
            local very_long_data = ("hello"):rep(201)
            local data_len = #very_long_data
            local encrypted_data = {}
            local segment_size = 100
            for i = 1, data_len, segment_size do
                local ceiling = math.min(i+segment_size-1, data_len)
                local encrypted, err = pub:encrypt(very_long_data:sub(i, ceiling))
                if not encrypted then
                    ngx.say("failed to encrypt: ", err)
                    return
                end
                table.insert(encrypted_data, encrypted)
            end

            local priv, err = resty_rsa:new({ private_key = RSA_PRIV_KEY })
            if not priv then
                ngx.say("new rsa err: ", err)
                return
            end
            local decrypted_data = {}
            -- 你自己的分块逻辑应该在这里引入
            for _, data in ipairs(encrypted_data) do
                -- 每个data字符串的大小是128字节
                local decrypted, err = priv:decrypt(data)
                if not decrypted then
                    ngx.say("failed to decrypt ", err)
                    return
                end
                table.insert(decrypted_data, decrypted)
            end
            ngx.say(table.concat(decrypted_data) == very_long_data)

from lua-resty-rsa.

woshiyjs123 avatar woshiyjs123 commented on July 30, 2024

多谢,已经解决了

from lua-resty-rsa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.