no padding

This commit is contained in:
Dmitry Bespalov 2019-09-04 14:52:14 +02:00
parent 7e003e5106
commit 3f8ce4fdda
2 changed files with 4 additions and 4 deletions

View File

@ -22,13 +22,13 @@ class Crypto {
}
func aes256Enc(data: [UInt8], iv: [UInt8], key: [UInt8]) -> [UInt8] {
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).encrypt(data)
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .noPadding).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] {
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .zeroPadding).decrypt(data)
let result = try! AES(key: key, blockMode: CBC(iv: iv), padding: .noPadding).decrypt(data)
Logger.shared.log("aes256Dec(data=\(Data(data).toHexString()) iv=\(Data(iv).toHexString()) key=\(Data(key).toHexString())) => \(Data(result).toHexString())")
return result
}

View File

@ -10,8 +10,8 @@ final class CryptoTests: XCTestCase {
let (sk, pk) = Crypto.shared.secp256k1GeneratePair()
let secret = Crypto.shared.secp256k1ECDH(privKey: sk, pubKey: pk)
let iv = Crypto.shared.random(count: SecureChannel.blockLength)
let encrypted = Crypto.shared.aes256Enc(data: plaintextBytes, iv: iv, key: secret)
let decrypted = Crypto.shared.aes256Dec(data: encrypted, iv: iv, key: secret)
let encrypted = Crypto.shared.aes256Enc(data: Crypto.shared.iso7816_4Pad(data: plaintextBytes, blockSize: SecureChannel.blockLength), iv: iv, key: secret)
let decrypted = Crypto.shared.iso7816_4Unpad(data: Crypto.shared.aes256Dec(data: encrypted, iv: iv, key: secret))
let decryptedText = String(data: Data(decrypted), encoding: .utf8)
XCTAssertEqual(decryptedText, plaintext)