This blog is moved to
http://amalhashim.wordpress.com

Thursday, August 27, 2009

Creating a zip file using C#

Using the System.IO.Compression namespace in Codeplex a classlibrary project is going on name DotNetZip

The class library has a ZipFile class. Using this, you can create zip files using the below code

ZipFile zip= new ZipFile("MyNewZip.zip");

zip.AddDirectory("My Pictures", true); // AddDirectory recurses subdirectories

zip.Save();

1 comment:

Unknown said...

Hi Hashim,

Actually I am trying to decrypt he image file which is encrypted in ruby gem software

here's what I am trying to do.

I have a java code for decryptiion which is (attached below) and it looks same as what you have written in your java-decrypt function.

But i am ending up with this Execption :javax.crypto.BadPaddingException: Given final block not properly padded


ApplicationContext gridFsctx = new GenericXmlApplicationContext("SpringConfig.xml");
GridFsOperations gridFsmongoOperation = (GridFsOperations) gridFsctx.getBean("gridFsTemplate");

Query searchQuery=new Query(Criteria.where("filename").is("enc_BLR-0592313_page_0.jpg"));
GridFSDBFile gridFSDBFile = gridFsmongoOperation.findOne(searchQuery);

File file = new File("gridFSDBFile.out");
FileOutputStream fos1 = new FileOutputStream(file);
gridFSDBFile.writeTo(fos1);

File file1 = new File("gridFSDBFile.out");
byte[] bFile = new byte[(int) file1.length()];
FileInputStream fis = new FileInputStream(file1);
fis.read(bFile);

//decode the
Base64 base64 = new Base64();
byte[] decodedArr = base64.decode(bFile);
String temp = new String(decodedArr, "UTF-8");

byte[] decodedData=temp.getBytes(("UTF-8"));

byte[] decArr = Arrays.copyOfRange(decodedData, 24, bFile.length );
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(base64.decode("mkJmh3d2WLNXgmWIv4znTU+IXk7XczlInO9mXmvliBE=\n"), "AES"),new IvParameterSpec(Arrays.copyOfRange(decodedData, 8, 24 )));

BASE64Decoder decoder = new BASE64Decoder();
byte [] results = cipher.doFinal(decoder.decodeBuffer(new String(base64.encode(decArr))));