.net - C# Crypt returning null -
i have method:
public static string decryptfile(string sinputfilename, string skey) { descryptoserviceprovider des = new descryptoserviceprovider(); des.key = asciiencoding.ascii.getbytes(skey); des.iv = asciiencoding.ascii.getbytes(skey); filestream fsread = new filestream(sinputfilename, filemode.open, fileaccess.read); icryptotransform desdecrypt = des.createdecryptor(); cryptostream cryptostreamdecr = new cryptostream(fsread, desdecrypt, cryptostreammode.read); return new streamreader(cryptostreamdecr).readtoend(); } this crypt method:
public static void encryptfile(string sinputfilename, string soutputfilename, string skey) { filestream fsinput = new filestream(sinputfilename, filemode.open, fileaccess.read); filestream fsencrypted = new filestream(soutputfilename, filemode.create, fileaccess.write); descryptoserviceprovider des = new descryptoserviceprovider(); des.key = asciiencoding.ascii.getbytes(skey); des.iv = asciiencoding.ascii.getbytes(skey); icryptotransform desencrypt = des.createencryptor(); cryptostream cryptostream = new cryptostream(fsencrypted, desencrypt, cryptostreammode.write); byte[] bytearrayinput = new byte[fsinput.length]; fsinput.read(bytearrayinput, 0, bytearrayinput.length); cryptostream.write(bytearrayinput, 0, bytearrayinput.length); cryptostream.close(); fsinput.close(); fsencrypted.close(); } in crypt file, putting string commas contains array. here code pulling data:
ssecretkey = crypt.generatekey(); gchandle gch = gchandle.alloc(ssecretkey, gchandletype.pinned); string data = crypt.decryptfile(dencrypt, ssecretkey); crypt.zeromemory(gch.addrofpinnedobject(), ssecretkey.length * 2); gch.free(); string[] arr = data.split(','); now, after running putting break point on line of var , see it's null , not containing anything..
someone know problem?
Comments
Post a Comment