Fix decryption
This commit is contained in:
		
							parent
							
								
									1345125252
								
							
						
					
					
						commit
						8ecc55af1f
					
				@ -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 {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user