【问题标题】:RSA Encryption using SwiftyRSA使用 SwiftyRSA 进行 RSA 加密
【发布时间】:2018-07-30 15:43:26
【问题描述】:

我正在使用 SwiftyRSA 在我的应用程序中使用 RSA 加密。 我从服务器接收字符串格式的公钥,我想使用该字符串创建我的公钥,但我无法实现。 任何帮助将不胜感激。

【问题讨论】:

  • “使用该字符串创建我的公钥”是什么意思。您不能为自己分配与其他人相同的 RSA 公钥 - 这就是 RSA 现在的工作方式。
  • 嗯,我不知道,后端的人是这么说的。我该怎么办?
  • 这只是语义,不要说“我的”公钥,它实际上是您将使用的服务器的公钥。 “任何帮助”问题,包括这个问题,对于 stackoverflow 来说通常过于宽泛。顺便说一句,如果你在做客户端到服务器的加密,你几乎可以肯定应该使用 TLS 而不是一些本土方案。

标签: swift rsa public-key-encryption


【解决方案1】:

最后我能够通过在 swift """ 中使用这个字符串文字来创建 .pem 文件来解决这个问题,从而解决了这个问题。

示例如下:

// This creates a multiline public key
fileprivate var pbKey = """
                        blah blah
                        blah blah
                        public key
                        """

// Then you use that public key in your pem file
let publicKey = try PublicKey(pemEncoded: pbKey)
let clear = try ClearMessage(string: "Clear Text", using: .utf8)
let encrypted = try clear.encrypted(with: publicKey, padding: .OAEP)

【讨论】:

    猜你喜欢
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 2017-07-02
    • 2017-06-25
    • 2014-12-13
    • 2012-04-07
    相关资源
    最近更新 更多