c# - the input data is not a complete block while decrypting the cipher Text -


can me problem? here decrypt function code.

    public  static string decryptstringaes(string ciphertext)     {         if (ciphertext == null || ciphertext.length <= 0)             throw new argumentnullexception("plaintext");         string key = "0102030405060708";         string iv = "1020304050607080";         if (key == null || key.length <= 0)             throw new argumentnullexception("key");         if (iv == null || iv.length <= 0)             throw new argumentnullexception("iv");         byte[] bytearraytodecrypt = encoding.ascii.getbytes(ciphertext);           aescryptoserviceprovider keydecrypt = new aescryptoserviceprovider();         keydecrypt.blocksize = 128;         keydecrypt.keysize = 128;         keydecrypt.key = system.text.encoding.utf8.getbytes(key);         keydecrypt.iv = system.text.encoding.utf8.getbytes(iv);         keydecrypt.padding = paddingmode.pkcs7;         keydecrypt.mode = ciphermode.cbc;          icryptotransform crypto1 = keydecrypt.createdecryptor(keydecrypt.key, keydecrypt.iv);          byte[] returnbytearray = crypto1.transformfinalblock(bytearraytodecrypt, 0, bytearraytodecrypt.length);         crypto1.dispose();         return convert.tobase64string(returnbytearray);     } 

not sure question is.

aes in cbc mode block cipher, input , output in block sized chunks.

if input encryption might not multiple of block size padding can added (pkcs#7 padding in question code) data encrypted make so. output multiple of block size.

because of question not make sense, encrypted data multiole of block size if pkcs#7 padding used (as in code).

on decryption decrypted output multiple of block size , padding can removed.

by specifying pkcs#7 padding int apiu call padding/de-padding happen in api.

there other modes such ctr output same length input, in general "streaming" modes , have own complications such never using same nonce same key.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -