Skip to content

Commit

Permalink
pod RNCryptor
Browse files Browse the repository at this point in the history
Keychain: encrypting data before saving to encrypted store. So you can decrypt while you decrypt.
  • Loading branch information
RealBonus committed Mar 9, 2018
1 parent 84e8a87 commit 049a707
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@
"${BUILT_PRODUCTS_DIR}/MessageKit/MessageKit.framework",
"${BUILT_PRODUCTS_DIR}/MyLittlePinpad/MyLittlePinpad.framework",
"${BUILT_PRODUCTS_DIR}/QRCodeReader.swift/QRCodeReader.framework",
"${BUILT_PRODUCTS_DIR}/RNCryptor/RNCryptor.framework",
"${BUILT_PRODUCTS_DIR}/Swinject/Swinject.framework",
"${BUILT_PRODUCTS_DIR}/SwinjectStoryboard/SwinjectStoryboard.framework",
);
Expand All @@ -859,6 +860,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MessageKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MyLittlePinpad.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QRCodeReader.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNCryptor.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Swinject.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwinjectStoryboard.framework",
);
Expand Down
16 changes: 14 additions & 2 deletions Adamant/Services/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@

import Foundation
import KeychainAccess
import RNCryptor

class KeychainStore: SecuredStore {
let keychain = Keychain(service: "im.adamant")
private let 🍩 = "hello titty" // For AppStore builds, we use a real password

func get(_ key: String) -> String? {
return keychain[key]
if let rawData = keychain[key],
let encryptedData = Data(base64Encoded: rawData),
let data = try? RNCryptor.decrypt(data: encryptedData, withPassword: 🍩),
let string = String(data: data, encoding: .utf8) {
return string
}

return nil
}

func set(_ value: String, for key: String) {
keychain[key] = value
if let data = value.data(using: .utf8) {
let encryptedString = RNCryptor.encrypt(data: data, withPassword: 🍩).base64EncodedString()
try? keychain.set(encryptedString, key: key)
}
}

func remove(_ key: String) {
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target 'Adamant' do

pod 'Alamofire' # Network
pod 'KeychainAccess' # Keychain
pod 'RNCryptor' # Cryptor

# Swinject DI
pod 'Swinject'
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PODS:
- MessageKit (0.13.1)
- MyLittlePinpad (0.2.2)
- QRCodeReader.swift (8.1.1)
- RNCryptor (5.0.2)
- Swinject (2.2.0)
- SwinjectStoryboard (1.1.2):
- Swinject (~> 2.1)
Expand All @@ -28,6 +29,7 @@ DEPENDENCIES:
- MessageKit
- MyLittlePinpad
- QRCodeReader.swift
- RNCryptor
- Swinject
- SwinjectStoryboard

Expand All @@ -41,9 +43,10 @@ SPEC CHECKSUMS:
MessageKit: fc74d71d9b05385138d47b3a4b7beef5c687daf1
MyLittlePinpad: 8b24927da4c1c8daa64ab1b9f142a8329f480745
QRCodeReader.swift: b164a681887de276d405ff02bce854d82cd6360b
RNCryptor: 59b9f92e9fa8a1af74c32dc6b1af5e30ff5e1b64
Swinject: 4ca48bca7de5f398229a26abe1ac902b9f3ee541
SwinjectStoryboard: 92e75763c3299cdf627bef98a5180dc894864336

PODFILE CHECKSUM: 54b55788f642fe125eb02ede607957e5138bf2a1
PODFILE CHECKSUM: f56801713dedd8f5b2d1ec95f822fbbce22dc294

COCOAPODS: 1.4.0

0 comments on commit 049a707

Please sign in to comment.