【问题标题】:JWT RSA Encryption - Would this be be slow with many requests?JWT RSA Encryption - 有很多请求会很慢吗?
【发布时间】:2016-03-24 17:57:08
【问题描述】:

我正在考虑使用带有 RSA 加密的 JSON Web 令牌,但我担心这会很慢。我的逻辑是 TLS 使用 RSA 加密来交换密钥,但之后使用 AES 加密,因为公钥/私钥解密速度很慢。

【问题讨论】:

    标签: encryption rsa jwt public-key-encryption


    【解决方案1】:

    这听起来像是你正朝着一个危险的方向前进。有几种方法可以实现 JWT:

    • HMAC
    • RSA 签名不是加密
    • ECDSA 签名

    RSA 加密和 AES 都不是适合这项工作的工具。 You want authentication, not encryption.

    如果您想要速度,我会推荐 HMAC。具有 SHA2 系列哈希函数;例如SHA-256。

    【讨论】:

      【解决方案2】:

      这是来自Go implementation 的基准。 BenchmarkHMACSign/HS256-12 500000 3421 ns/op BenchmarkHMACSign/HS384-12 300000 4014 ns/op BenchmarkHMACSign/HS512-12 300000 4131 ns/op BenchmarkHMACCheck/HS256-12 200000 8737 ns/op BenchmarkHMACCheck/HS384-12 200000 9506 ns/op BenchmarkHMACCheck/HS512-12 200000 9634 ns/op BenchmarkRSASign/1024-bit-12 2000 567073 ns/op BenchmarkRSASign/2048-bit-12 500 2569703 ns/op BenchmarkRSASign/4096-bit-12 100 14835903 ns/op BenchmarkRSACheck/1024-bit-12 50000 35438 ns/op BenchmarkRSACheck/2048-bit-12 20000 75855 ns/op BenchmarkRSACheck/4096-bit-12 10000 204811 ns/op

      【讨论】:

        猜你喜欢
        • 2013-03-24
        • 1970-01-01
        • 1970-01-01
        • 2017-10-11
        • 1970-01-01
        • 1970-01-01
        • 2018-06-28
        • 2019-09-03
        • 1970-01-01
        相关资源
        最近更新 更多