Hi,
I'm tried all the different samples for Managed Rijndael I found in the internet for .NET, like the one attached.
Everytime I crypt an array of bytes whitch has a size of 128 Bytes (16*8), the encrypted result has a size of 144 Bytes (128+16).
Everywhere you can read that Rijndaels AES is an blockchiffre which keeps the size the same as the origin, or does it not?
I tried a source of 127 Bytes for example and the target grows to 128, thats okay. But the exact size of 128 does not work correct. The same happens to 256 Bytes, they grow.
Btw: The crypting and decrypting works correctly. But size matters to.
I need: source 128 Bytes -> encrypted 128 Byte-> decrypted 128 Byte.
Does any one have the same problem or an idea to solve it? Help is appreciated .
Example, but any other sample using Managed Rijndael I found does the same fault:
Thx, LastUser
I'm tried all the different samples for Managed Rijndael I found in the internet for .NET, like the one attached.
Everytime I crypt an array of bytes whitch has a size of 128 Bytes (16*8), the encrypted result has a size of 144 Bytes (128+16).
Everywhere you can read that Rijndaels AES is an blockchiffre which keeps the size the same as the origin, or does it not?
I tried a source of 127 Bytes for example and the target grows to 128, thats okay. But the exact size of 128 does not work correct. The same happens to 256 Bytes, they grow.
Btw: The crypting and decrypting works correctly. But size matters to.
I need: source 128 Bytes -> encrypted 128 Byte-> decrypted 128 Byte.
Does any one have the same problem or an idea to solve it? Help is appreciated .
Example, but any other sample using Managed Rijndael I found does the same fault:
VB.NET:
Imports System.Security.Cryptography
Imports System.IO
Public Function EncryptString128Bit(ByVal bytValue As Byte(), ByVal bytKey As Byte()) As Byte()
Dim bytEncoded() As Byte
Dim bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62}
Dim objMemoryStream As New MemoryStream()
Dim objCryptoStream As CryptoStream
Dim objRijndaelManaged As RijndaelManaged
ReDim bytEncoded(0)
objRijndaelManaged = New RijndaelManaged()
objCryptoStream = New CryptoStream(objMemoryStream, objRijndaelManaged.CreateEncryptor(bytKey, bytIV), CryptoStreamMode.Write)
objCryptoStream.Write(bytValue, 0, bytValue.Length)
objCryptoStream.FlushFinalBlock()
bytEncoded = objMemoryStream.ToArray
ReDim Preserve bytEncoded(255)
objMemoryStream.Close()
objCryptoStream.Close()
objMemoryStream = Nothing
objCryptoStream = Nothing
Return bytEncoded
End Function
Public Function DecryptString128Bit(ByVal bytDataToBeDecrypted As Byte(), ByVal bytDecryptionKey As Byte()) As Byte()
Dim bytTemp() As Byte
Dim bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62}
Dim objRijndaelManaged As New RijndaelManaged()
Dim objMemoryStream As MemoryStream
Dim objCryptoStream As CryptoStream
Dim strReturnString As String = String.Empty
ReDim bytTemp(bytDataToBeDecrypted.Length)
objMemoryStream = New MemoryStream(bytDataToBeDecrypted)
objCryptoStream = New CryptoStream(objMemoryStream, objRijndaelManaged.CreateDecryptor(bytDecryptionKey, bytIV), CryptoStreamMode.Read)
objCryptoStream.Read(bytTemp, 0, bytTemp.Length)
objMemoryStream.Close()
objCryptoStream.Close()
objMemoryStream = Nothing
objCryptoStream = Nothing
Return bytTemp
End Function
Thx, LastUser