티스토리 뷰

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
  }
}

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함