使用 SwiftyRSA 的 RSA 加密
RSA Encryption using SwiftyRSA
我正在使用 SwiftyRSA 在我的应用程序中使用 RSA 加密。
我从服务器收到字符串格式的 public 密钥,我想使用该字符串创建我的 public 密钥,但我无法实现。
任何帮助将不胜感激。
最后,我能够通过在 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)
我正在使用 SwiftyRSA 在我的应用程序中使用 RSA 加密。 我从服务器收到字符串格式的 public 密钥,我想使用该字符串创建我的 public 密钥,但我无法实现。 任何帮助将不胜感激。
最后,我能够通过在 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)