AES encryption error: The input data is not a complete block?

ConditionRacer

Here's the encryption method:

public static byte[] Encrypt(byte[] plaintext, byte[] key)
{
    using (var aes = Aes.Create())
    {
        aes.BlockSize = 128;
        aes.Mode = CipherMode.ECB;
        aes.Padding = PaddingMode.None;

        var iv = new byte[16];
        for (int i = 0; i < iv.Length; i++)
            iv[i] = 0;
        aes.IV = iv;

        var encryptor = aes.CreateEncryptor(key, aes.IV);
        using(var target = new MemoryStream())
        using (var cs = new CryptoStream(target, encryptor, CryptoStreamMode.Write))
        {
            using (var source = new StreamWriter(cs))
                source.Write(plaintext);
            return target.ToArray();
        }
    }
}

And how I'm calling it:

var key = new byte[16] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var plaintext = new byte[16] { 128, 0, 112, 0, 96, 0, 80, 0, 64, 0, 48, 0, 32, 0, 16, 0 };

But it keeps throwing an exception at source.Write(plaintext) that says it's not a complete block? I'm using a 16 byte/ 128 bit array with the block size set to 128. I don't understand what's wrong?

Also, just to head off any suggestions that ECB is bad etc, this is not for production, I'm just playing around.

SLaks

StreamWriter writes UTF8 text characters to a stream.
You're writing plaintext.ToString() as text for the ciphertext.

This returns "System.Byte[]", which does not translate into 16 bytes of UTF8.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

AES Encryption in Swift?

From Java

Error in Key Size I'm Using for AES Encryption C#

From Dev

AES256 Encryption/Decryption Error+ IOS SDK 7

From Dev

AES encryption error: The input data is not a complete block?

From Dev

AES Decryption ERROR: android pad block corrupted

From Dev

Friedman test unreplicated complete block design error

From Dev

Golang AES ECB Encryption

From Dev

Bouncy Castle AES Encryption - providing input in blocks

From Dev

Wrong AES encryption

From Dev

AES Encryption/Decryption : Given final block not properly padded

From Dev

Encryption AES 256 Input Plaintext Length Issue

From Dev

AES CTR encryption and decryption

From Dev

Golang AES StreamReader encryption - Example omits any authentication of the encrypted data

From Dev

OpenSSL AES-256-CBC Encryption Error, "wrong final block length" Ruby

From Dev

Parse error in a `do` block on input `<-`

From Dev

Error when decrypt input data longer than 15 chars with AES256 and Node.js

From Dev

IV must be 16 bytes long error in AES encryption

From Dev

javax.crypto.BadPaddingException error during AES encryption

From Dev

Java AES encryption: Given final block not properly padded

From Dev

Unknown Error in AES CBC encryption pycrypto 2.6

From Dev

Encryption using Rijndael AES using 128 bit keys, 16 byte blocks and cipher block chaining

From Dev

AES256 Encryption/Decryption Error+ IOS SDK 7

From Dev

AES Encryption Given Final Block Not Properly Padded

From Dev

AES-128-ECB decryption: The input data is not a complete block

From Dev

AES 256 bit encryption with 256 block size in iOS

From Dev

If a user has access to multiple encrypted pieces of data with AES encryption, would they be able to guess the encryption key?

From Dev

javax.crypto.BadPaddingException error during AES encryption

From Dev

AES decryption The input data is not a complete block

From Dev

C# AES encryption: Starting/Ending space throw CryptographicException: 'The input data is not a complete block

Related Related

  1. 1

    AES Encryption in Swift?

  2. 2

    Error in Key Size I'm Using for AES Encryption C#

  3. 3

    AES256 Encryption/Decryption Error+ IOS SDK 7

  4. 4

    AES encryption error: The input data is not a complete block?

  5. 5

    AES Decryption ERROR: android pad block corrupted

  6. 6

    Friedman test unreplicated complete block design error

  7. 7

    Golang AES ECB Encryption

  8. 8

    Bouncy Castle AES Encryption - providing input in blocks

  9. 9

    Wrong AES encryption

  10. 10

    AES Encryption/Decryption : Given final block not properly padded

  11. 11

    Encryption AES 256 Input Plaintext Length Issue

  12. 12

    AES CTR encryption and decryption

  13. 13

    Golang AES StreamReader encryption - Example omits any authentication of the encrypted data

  14. 14

    OpenSSL AES-256-CBC Encryption Error, "wrong final block length" Ruby

  15. 15

    Parse error in a `do` block on input `<-`

  16. 16

    Error when decrypt input data longer than 15 chars with AES256 and Node.js

  17. 17

    IV must be 16 bytes long error in AES encryption

  18. 18

    javax.crypto.BadPaddingException error during AES encryption

  19. 19

    Java AES encryption: Given final block not properly padded

  20. 20

    Unknown Error in AES CBC encryption pycrypto 2.6

  21. 21

    Encryption using Rijndael AES using 128 bit keys, 16 byte blocks and cipher block chaining

  22. 22

    AES256 Encryption/Decryption Error+ IOS SDK 7

  23. 23

    AES Encryption Given Final Block Not Properly Padded

  24. 24

    AES-128-ECB decryption: The input data is not a complete block

  25. 25

    AES 256 bit encryption with 256 block size in iOS

  26. 26

    If a user has access to multiple encrypted pieces of data with AES encryption, would they be able to guess the encryption key?

  27. 27

    javax.crypto.BadPaddingException error during AES encryption

  28. 28

    AES decryption The input data is not a complete block

  29. 29

    C# AES encryption: Starting/Ending space throw CryptographicException: 'The input data is not a complete block

HotTag

Archive