no padding
This commit is contained in:
parent
7e003e5106
commit
3f8ce4fdda
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue