encryption - Decrypt the contents of a folder - VB.NET -
i've been tasked making encryption programme , part of task encrypt/decrypt folder.
the encryption works how want when seek decrypt gives me error:
"length of info decrypt invalid".
all can i've changed i'm using des.createdecryptor instead of des.createencryptor in encryption code. though looks there's more work.
just wondering how prepare really. i'll leave relevant portion of code below.
dim folderinfo new directoryinfo(folderpath) each file in directory.getfiles(folderinfo.fullname) dim outputfile string outputfile = file dim fsinput new filestream(file, filemode.open, fileaccess.read) dim bytearrayinput(fsinput.length) byte fsinput.read(bytearrayinput, 0, bytearrayinput.length) fsinput.close() dim skey string skey = encrypt dim fsdecrypted new filestream(file, filemode.create, fileaccess.write) dim des new descryptoserviceprovider des.key = asciiencoding.ascii.getbytes(skey) des.iv = asciiencoding.ascii.getbytes(skey) dim desdecrypt icryptotransform desdecrypt = des.createdecryptor() dim cryptostream new cryptostream(fsdecrypted, desdecrypt, cryptostreammode.write) cryptostream.write(bytearrayinput, 0, bytearrayinput.length) cryptostream.close() fsdecrypted.close() txtdecrypt.text = "all files decrypted"
you've done classic error when instantiating array. array should instantiated size (n - 1) n number of elements. set right size, have subtract 1 fsinput length.
dim bytearrayinput(fsinput.length - 1) byte vb.net encryption
No comments:
Post a Comment