Pem文件如下
Public Key
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA0bipoOhkkvPxcsyOzcqsIUeVe0+iwe8W7N4EbHZMgujRERu1TPpy
UcCO0uuKmm1TU09Kl40rRvDbtgB1YcGV3FPnNp3sOyFVsdyZ5bzxZtyyLrSWtj/n
bLnGwaG9xJSwd2R/pTQLzOLV5KldwD2eUb3Z4Z4e9Z8II7eWgGaCLLqbrtEAa05N
EqARckxrzJ1S3j+59h4AQovF72KI90/kRPryT2OGDiVlJ6CTjn2ZnTYcx65X6Rwf
AeJKHZAGhw96j9tXyS+dJcXy4IBUTi3PXw0aEfhHQr/JsSHuMp/8mrhVJEokXb1C
gKDZgJXujpGhCBdztHBAJxLBQMlODg7srwIDAQAB
-----END RSA PUBLIC KEY-----
但是我有一串公钥为
MIIBCgKCAQEA0bipoOhkkvPxcsyOzcqsIUeVe0+iwe8W7N4EbHZMgujRERu1TPpy
UcCO0uuKmm1TU09Kl40rRvDbtgB1YcGV3FPnNp3sOyFVsdyZ5bzxZtyyLrSWtj/n
bLnGwaG9xJSwd2R/pTQLzOLV5KldwD2eUb3Z4Z4e9Z8II7eWgGaCLLqbrtEAa05N
EqARckxrzJ1S3j+59h4AQovF72KI90/kRPryT2OGDiVlJ6CTjn2ZnTYcx65X6Rwf
AeJKHZAGhw96j9tXyS+dJcXy4IBUTi3PXw0aEfhHQr/JsSHuMp/8mrhVJEokXb1C
gKDZgJXujpGhCBdztHBAJxLBQMlODg7srwIDAQAB
我想做什么?
我想使用此公用密钥来加密我的Secret Key
以便将其传递到服务器。我生成了一个动态32byte key
,它的形式为UInt8数组。
到目前为止我一直在尝试什么?
self.PUB_KEY = [UInt8](Data(base64Encoded: self.PUB_KEY_B64)!)
使用上面的行,我从上面的公共密钥字符串生成一个UInt8数组。
func encryptKey() -> [UInt8] {
let publicKey = try! PublicKey(pemEncoded: Data(bytes: self.PUB_KEY).base64EncodedString())
let clearMessage = ClearMessage(data: Data(bytes: self.syncKey))
return [UInt8]((try! clearMessage.encrypted(with: publicKey, padding: .OAEP)).data)
}
使用上面的代码,我正在加密密钥。
问题面对
只要此加密数据到达服务器,它就会显示错误
routines:rsa_ossl_private_decrypt:data greater than mod len