Fix decryption

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2019-09-21 22:39:59 +02:00
1 parent 1345125252
commit 8ecc55af1f
2 files changed
+6 -3

No files matched your search

@@ -18,6 +18,7 @@ package com.ionspin.kotlin.crypto.symmetric
import com.ionspin.kotlin.crypto.SRNG
import com.ionspin.kotlin.crypto.chunked
import com.ionspin.kotlin.crypto.toHexString
import com.ionspin.kotlin.crypto.xor
/**
@@ -145,10 +146,10 @@ class AesCbc internal constructor(val aesKey: AesKey, val mode: Mode, initializa
Mode.DECRYPT -> {
if (currentOutput.isEmpty()) {
currentOutput = Aes.decrypt(aesKey, data) xor iv
previousEncrypted = data
} else {
currentOutput = Aes.decrypt(aesKey, data) xor previousEncrypted
}
previousEncrypted = data
currentOutput
}
}
@@ -38,7 +38,7 @@ class AesCbcTest {
val aesCbc = AesCbc(AesKey.Aes128Key(key), mode = Mode.ENCRYPT, initializationVector = iv.hexStringToUByteArray())
aesCbc.addData(plaintext.hexStringToUByteArray())
val encrypted = aesCbc.encrypt()
println("Decrypted: ${encrypted.toHexString()}")
println("Encrypted: ${encrypted.toHexString()}")
assertTrue {
expectedCipherText == encrypted.toHexString()
}
@@ -54,7 +54,7 @@ class AesCbcTest {
val aesCbc = AesCbc(AesKey.Aes128Key(key), mode = Mode.DECRYPT, initializationVector = iv.hexStringToUByteArray())
aesCbc.addData(cipherText.hexStringToUByteArray())
val decrypted = aesCbc.decrypt()
println("Encrypted: ${decrypted.toHexString()}")
println("Decrypted: ${decrypted.toHexString()}")
assertTrue {
expectedPlainText == decrypted.toHexString()
}
@@ -64,4 +64,6 @@ class AesCbcTest {
}