macOS, iOS
[iOS] RSA encryption
SweetDev
2021. 2. 28. 13:36
비밀번호를 평문으로 보내면 네트워크를 타고 가는 중에서 비번이 털릴 수도 있다. 그래서 만든것이 RSA encryption!
이렇게 서버개발자가 만들어준 public-key API를 호출해서 publicKey를 받고,
encrypted 해준다!
그렇게 해서 나온 encrypted랑, publicKey를 같이 Login시 보내주면 된다.
사용한 라이브러리는 : github.com/TakeScoop/SwiftyRSA
extension String {
func rsaEncryption(publicKey: String) -> String {
let publicKey = try! PublicKey(base64Encoded: publicKey)
let clear = try! ClearMessage(string: self, using: .utf8)
let encrypted = try! clear.encrypted(with: publicKey, padding: .PKCS1)
return encrypted.base64String
}
}