我正在接收base64
格式的模数和指数,并且我试图从中生成一个pemstring。
我已经尝试过swiftyrsa
和joseswift
,但是它不起作用
var mod = "qzZwIDyV13LHZe9hXf282Us5MHSXq08+XKQPqoVG/2gY5g/6/HywzD5ZS2C18OaeXUEJmIoCeYXW3zE1N9YCf8B9XPqG9wRO2Hh7QB4UlZh2nUx43n7mPA9Xf8Ne7gLFfOu6OGo8w/SBfzFq1EojqGxtgiyBIG9FJll6VqE0wqE="
var expo = "AQAB"
var dict:[String:String] = ["kty":"RSA","n":mod,"e":expo]//"{"kty":"RSA","n":mod,"e":expo}"
do{
let jsondata = try JSONEncoder().encode(dict);
let jwk = try! RSAPublicKey(data: jsondata)
let publicKey: SecKey = try! jwk.converted(to: SecKey.self)
var str = ""
var error:Unmanaged<CFError>?
if let cfdata = SecKeyCopyExternalRepresentation(publicKey, &error) {
let data:Data = cfdata as Data
str = data.base64EncodedString()
print(str);
}
}catch{
}
生成的字符串如下
MIGJAoGBAKs2cCA8lddyx2XvYV39vNlLOTB0l6tPPlykD6qFRv9oGOYP+vx8sMw+WUtgtfDmnl1BCZiKAnmF1t8xNTfWAn/AfVz6hvcETth4e0AeFJWYdp1MeN5+5jwPV3/DXu4CxXzrujhqPMP0gX8xatRKI6hsbYIsgSBvRSZZelahNMKhAgMBAAE=
,但实际结果应根据该网站创建的内容 https://superdry.apphb.com/tools/online-rsa-key-converter