evgenyneu / keychain-swift

Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.
MIT License
2.82k stars 345 forks source link

Store credit card info #133

Closed vitbulio closed 4 years ago

vitbulio commented 4 years ago

Hello. How can I save credit card info into Keychain? From apple docs: "You can store other secrets that the user explicitly cares about, such as credit card information or even short notes" but there's no info how can do this.

evgenyneu commented 4 years ago

Hi, you can store a password like any other text in Keychain:

let keychain = KeychainSwift()
keychain.set("password123", forKey: "my strong password")
print(keychain.get("my strong password"))
vitbulio commented 4 years ago

Hi, you can store a password like any other text in Keychain:

let keychain = KeychainSwift()
keychain.set("password123", forKey: "my strong password")
print(keychain.get("my strong password"))

If i store internet password, then key is password from textfield. It's ok. So, if i want to store credit card info, then can I store like this?

let keychain = KeychainSwift()
let cardNumber = "1111 1111 1111 1111"
let cardHolder = "Name Surname"
let expireDate = "12/22"
let cvv = "111" 
let storeData = cardNumber + "." cardHolder + "."  + expireDate + "." + cvv
keychain.set(storeData, forKey: randomPassword)
print(keychain.get("randomPassword"))
evgenyneu commented 4 years ago

There is no need to make a key a random password, since keychain stores the text securely, no other apps can read it. I would just call it something simple:

keychain.set(storeData, forKey: "credit card")

Also, would store number, holder, date, cvv as separate keys for simplicity.

vitbulio commented 4 years ago

There is no need to make a key a random password, since keychain stores the text securely, no other apps can read it. I would just call it something simple:

keychain.set(storeData, forKey: "credit card")

Also, would store number, holder, date, cvv as separate keys for simplicity.

Thanks a lot Evgenii!