padding
This commit is contained in:
parent
d6aecd5106
commit
053ec65d48
|
@ -21,11 +21,15 @@ class Crypto {
|
||||||
}
|
}
|
||||||
|
|
||||||
func aes256Enc(data: [UInt8], iv: [UInt8], key: [UInt8]) -> [UInt8] {
|
func aes256Enc(data: [UInt8], iv: [UInt8], key: [UInt8]) -> [UInt8] {
|
||||||
try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).encrypt(data)
|
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).encrypt(data)
|
||||||
|
Logger.shared.log("aes256Enc(data=\(Data(data).toHexString()) iv=\(Data(iv).toHexString()) key=\(Data(key).toHexString())) => \(Data(result).toHexString())")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func aes256Dec(data: [UInt8], iv: [UInt8], key: [UInt8]) -> [UInt8] {
|
func aes256Dec(data: [UInt8], iv: [UInt8], key: [UInt8]) -> [UInt8] {
|
||||||
try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).decrypt(data)
|
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).decrypt(data)
|
||||||
|
Logger.shared.log("aes256Dec(data=\(Data(data).toHexString()) iv=\(Data(iv).toHexString()) key=\(Data(key).toHexString())) => \(Data(result).toHexString())")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func aes256CMac(data: [UInt8], key: [UInt8]) -> [UInt8] {
|
func aes256CMac(data: [UInt8], key: [UInt8]) -> [UInt8] {
|
||||||
|
|
|
@ -162,10 +162,11 @@ class SecureChannel {
|
||||||
|
|
||||||
func oneShotEncrypt(data: [UInt8]) -> [UInt8] {
|
func oneShotEncrypt(data: [UInt8]) -> [UInt8] {
|
||||||
self.iv = Crypto.shared.random(count: SecureChannel.blockLength)
|
self.iv = Crypto.shared.random(count: SecureChannel.blockLength)
|
||||||
let encrypted = Crypto.shared.aes256Enc(data: data, iv: iv, key: secret!)
|
let paddedData = Crypto.shared.iso7816_4Pad(data: data, blockSize: SecureChannel.blockLength)
|
||||||
|
let encrypted = Crypto.shared.aes256Enc(data: paddedData, iv: iv, key: secret!)
|
||||||
let result = [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())")
|
Logger.shared.log("oneShotEncrypt: iv=\(Data(iv).toHexString()) secret=\(Data(secret!).toHexString()) padded=\(Data(paddedData).toHexString()) encrypted=\(Data(encrypted).toHexString()) ==> \(Data(result).toHexString())")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue