1 20 21 package net.sourceforge.lightcrypto.test; 22 23 import junit.framework.TestCase; 24 import junit.framework.Assert; 25 26 import java.io.*; 27 28 import net.sourceforge.lightcrypto.SafeObject; 29 import net.sourceforge.lightcrypto.Key; 30 import net.sourceforge.lightcrypto.Stream; 31 32 42 public class StreamTest extends TestCase { 43 48 protected void setUp() throws IOException { 49 FileOutputStream outStr = new FileOutputStream(RunTest.TEMPFOLDER + "readable.txt"); 51 DataOutputStream dataStr = new DataOutputStream(outStr); 52 53 dataStr.writeBytes("This is a readable string inside a file"); 54 55 dataStr.flush(); 56 dataStr.close(); 57 58 outStr.close(); 59 } 60 61 66 public void testStream() throws Exception { 67 Key.generatekey(RunTest.TEMPFOLDER + "tempkey.key",new StringBuffer ("password")); 69 70 SafeObject k = new SafeObject(); 71 k = Key.loadkey(RunTest.TEMPFOLDER + "tempkey.key",new StringBuffer ("password")); 72 73 ByteArrayOutputStream bao = new ByteArrayOutputStream(); 74 DataOutputStream dao = new DataOutputStream(bao); 75 ByteArrayOutputStream bao2 = new ByteArrayOutputStream(); 76 DataOutputStream dao2 = new DataOutputStream(bao2); 77 78 Stream.encrypt(new FileInputStream(RunTest.TEMPFOLDER + "readable.txt"),dao,k,64); 79 Stream.decrypt(new ByteArrayInputStream(bao.toByteArray()),dao2,k,64); 80 81 82 Assert.assertEquals("This is a readable string inside a file", new String (bao2.toByteArray())); 83 84 dao.close(); 85 dao2.close(); 86 } 87 88 } 89 | Popular Tags |