log to encryption

This commit is contained in:
Dmitry Bespalov 2019-09-04 14:14:53 +02:00
parent 0cddf0fcf7
commit d6aecd5106
1 changed files with 7 additions and 1 deletions

View File

@ -1,3 +1,6 @@
import CryptoSwift
import Foundation
class SecureChannel {
static let secretLength = 32
static let blockLength = 16
@ -160,7 +163,10 @@ class SecureChannel {
func oneShotEncrypt(data: [UInt8]) -> [UInt8] {
self.iv = Crypto.shared.random(count: SecureChannel.blockLength)
let encrypted = Crypto.shared.aes256Enc(data: data, iv: iv, key: secret!)
return [UInt8(self.publicKey!.count)] + publicKey! + iv + encrypted
let result = [UInt8(self.publicKey!.count)] + publicKey! + iv + encrypted
Logger.shared.log("oneShotEncrypt: iv=\(Data(iv).toHexString()) secret=\(Data(secret!).toHexString()) encrypted=\(Data(encrypted).toHexString()) ==> \(Data(result).toHexString())")
return result
}
private func encryptAPDU(_ data: [UInt8]) -> [UInt8] {