Improve NFC history readers and prepare production build
This commit is contained in:
@ -40,7 +40,7 @@ class BrizziSamHelper {
|
||||
|
||||
static func mix(_ bArr: [UInt8], _ bArr2: [UInt8]) -> [UInt8] {
|
||||
guard !bArr2.isEmpty else {
|
||||
fatalError("empty security key")
|
||||
return bArr
|
||||
}
|
||||
|
||||
var bArr3 = [UInt8](repeating: 0, count: bArr.count)
|
||||
@ -82,11 +82,26 @@ class BrizziSamHelper {
|
||||
}
|
||||
|
||||
func generateSamRandom() -> String {
|
||||
let sam = BrizziSamHelper.mix(((BrizziSamHelper.encrypt(self.keyCard!, self.random)!).hexEncodedString()).hex2byte().bytes, ("0000000000000000").hex2byte().bytes).hexString().subString(from: 0, to: 16)
|
||||
guard
|
||||
let keyCard = self.keyCard,
|
||||
let encryptedCard = BrizziSamHelper.encrypt(keyCard, self.random)?.hexEncodedString()
|
||||
else {
|
||||
return ""
|
||||
}
|
||||
let sam = BrizziSamHelper.mix(encryptedCard.hex2byte().bytes, ("0000000000000000").hex2byte().bytes).hexString().subString(from: 0, to: 16)
|
||||
guard sam.count == 16 else {
|
||||
return ""
|
||||
}
|
||||
let sams = sam[sam.index(sam.startIndex, offsetBy: 2)..<sam.index(sam.startIndex, offsetBy: 16)] + sam[sam.startIndex..<sam.index(sam.startIndex, offsetBy: 2)]
|
||||
let result = (BrizziSamHelper.encrypt((BrizziSamHelper.mix(("1122334455667788").hex2byte().bytes, (self.keyCard!).hex2byte().bytes).hexString()), self.random)!).hexEncodedString().subString(from: 0, to: 16)
|
||||
guard let encryptedResult = BrizziSamHelper.encrypt((BrizziSamHelper.mix(("1122334455667788").hex2byte().bytes, keyCard.hex2byte().bytes).hexString()), self.random)?.hexEncodedString() else {
|
||||
return ""
|
||||
}
|
||||
let result = encryptedResult.subString(from: 0, to: 16)
|
||||
|
||||
return result + (BrizziSamHelper.encrypt((BrizziSamHelper.mix(String(sams).hex2byte().bytes, result.hex2byte().bytes)).hexString(), self.random)!).hexEncodedString()
|
||||
guard let finalResult = BrizziSamHelper.encrypt((BrizziSamHelper.mix(String(sams).hex2byte().bytes, result.hex2byte().bytes)).hexString(), self.random)?.hexEncodedString() else {
|
||||
return result
|
||||
}
|
||||
return result + finalResult
|
||||
}
|
||||
|
||||
private static func crypt(input: Data, keyData: Data, ivData: Data?, operation: CCOperation) -> Data? {
|
||||
|
||||
Reference in New Issue
Block a user