encryption - C# Rijndael IV size doesn't match block size, while it should -
i have following code:
private void encryptfile(string inputfile, string outputfile, string pass) { try { string password = @pass; unicodeencoding ue = new unicodeencoding(); byte[] key = ue.getbytes(password); byte[] iv = new byte[128]; for(int =0; < iv.length; i++) { iv[i] = convert.tobyte(true); } string cryptfile = outputfile; filestream fscrypt = new filestream(cryptfile, filemode.create); rijndaelmanaged rmcrypto = new rijndaelmanaged(); messagebox.show(rmcrypto.blocksize + "\n" + iv.length); cryptostream cs = new cryptostream(fscrypt, rmcrypto.createencryptor(key, iv), cryptostreammode.write); filestream fsin = new filestream(inputfile, filemode.open); int data; while ((data = fsin.readbyte()) != -1) cs.writebyte((byte)data); fsin.close(); cs.close(); fscrypt.close(); } catch(exception ex) { //messagebox.show("encryption failed!", "error"); messagebox.show(ex.message); } }
but have problem iv size. using simple message box found (probably) block size 128. so, set iv 128 bytes array full of "1" values test. first message box confirms blocksize , iv array length both 128. however, exception saying specified initialization vector (iv) not match block size algorithm.
why , how fix issue?
aes block size 128 bits. not bytes. bits.
the winner of aes contest, rijndael, supports block , key sizes of 128, 192, , 256 bits, in aes block size 128 bits. block sizes not adopted aes standard
Comments
Post a Comment